MySQL Forums
Forum List  »  PHP

Need some advice in fixing this code...
Posted by: Intelli Nexus
Date: October 01, 2007 08:29PM

I have written a code that gathers an ip address from a database and then fetches its "as" number and stores the "as" number back into its corresponding location. If you have the patience, please have a have a look at my code else you can directly jump to my question at the end of my post. Here's the code:

DB Structure:
id, ip, asn

PHP Code:
<?php
include "conf_global.php";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$sql_ip = "SELECT * FROM ".$table_main." WHERE asn=0";
echo $sql_ip."<br>";
$result_ip = mysql_query($sql_ip);
echo $result_ip;

while($row_ip = mysql_fetch_assoc($result_ip)) {
curl_setopt($ch, CURLOPT_POSTFIELDS,
"action=do_whois&family=ipv4&method_whois=whois&bulk_paste=".$row_ip['ip']."&submit_paste=Submit");
echo "<br>".$row_ip[ip];
$result = curl_exec ($ch);

$pattern = "/[0-9]{1,9}\s{3,4}[|]\s[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/";
preg_match($pattern,$result,$req_info);

$pattern_for_ASN = "/[0-9]{1,9}/";
preg_match($pattern_for_ASN,$req_info[0],$asn);

echo "<br>".$asn[1].$asn[2];
$sql_asn = "UPDATE ".$table_main." SET asn = '$asn[0]' WHERE ip='$row_ip[ip]'";
echo $sql_asn;
$result_asn = mysql_query($sql_asn);
}

curl_close ($ch);
?>

Workflow:

Everytime I execute this script, it checks the database for empty asn numbers and fetches those ip numbers and then works on them. The script works fine for a small database but what would I do in the case of a large database? In my other post, I was suggested to look into pagination but I don't know how to relate the concepts.

Basically the question is "How would I execute a limited number of queries and after executing a limited set of queries, I would Meta Refresh the page and then continue from where I left off the previous time... " Please advice...

Options: ReplyQuote


Subject
Written By
Posted
Need some advice in fixing this code...
October 01, 2007 08:29PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.