View Single Post
Old 03-14-2004, 03:54 PM   #2
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
PHP Code:
<?php 
show_source
("wrapper.php"); 
exit; 
error_reporting(E_FATAL); 

$db "phpdig"
$threads 6


//Make connection 
$link mysql_connect('localhost''root'''); 
if (!
$link) { 
die(
'Could not connect: ' mysql_error()); 


//Select DB 
$db_selected mysql_select_db($db$link); 
if (!
$db_selected) { 
   die (
'Can\\'use $db ' . mysql_error()); 



//How many sites are currently being crawled? 
$SQL = "select locked from sites where locked = 1"; 

$result = mysql_query($SQL); 
if (!$result) { 
   die('
Invalid query' . mysql_error()); 


$num_rows = mysql_num_rows($result); 

//If num_rows (sites currently crawled > than threads we want to run exit. 
if($num_rows > $threads) 

  //Drop out we dont need to initiate any more crawlers 
  echo "Doing nothing..."; 
  exit; 

else 

   //The amount of threads we should start 
   $threads = $threads - ($num_rows - 1); 


   //Find sites currently not being crawled 
   $SQL2 = "select site_url from sites where locked = 0"; 
   $result2 = mysql_query($SQL2); 
   if(!$result2) 
   { 
       die('
Invalid query: ' . mysql_error()); 
   } 
   else 
   { 
    for($i = 0; $i < $threads; $i++) 
    { 
       $rowNum = rand(0, mysql_num_rows($result2)); 
       mysql_data_seek($result2, $rowNum); 
       $tmp =  mysql_fetch_row($result2); 

       $url = parse_url($tmp[0]); 
       $cmd = "screen -A -m -d -S ".$url[host]."_phpdig php -f spider.php ".$tmp[0]; 
       system($cmd); 
    } 
   } 


mysql_close($link); 

?>
Hi. I copied the code here for ease of read. One thing I noticed is that $rowNum is r****m so it might be possible to get the same $rowNum more than one time in the loop.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote