Hello All...

I wanted to write a program that would search google for specific
keywords from my database, and report to me if it found my domain, and
if so what page it was on.

Well it works, and it's very cool I might add, but then it fails...  
:(   But it doesn't fail right away.. I have had it fail as fast as 5
mins into exec, and as long as 1 1/2 hours into exec... and when it does
fail, it spits out 1 error over, and over, and over, just as fast as it
can (i think it gets stuck in the "for").. and the error says something
about "invalid file handle resource"...

I am testing it with 4 domains, and 90 keywords, and only having it
search the first 50 pages.. It takes a domain from mysql and then gets
the list of keywords to check. It then calls google and checks each
keyword page for the key domain.

Below is a copy of my code as it stands right now. I don't expect anyone
to have a quick answer to this problem, but I am hopeful that someone
might see something in the code that could be done better..
hopefuly....   :)

BTW.. I am running FreeBSD/3.4 and PHP/4.0.2


<?php

###############################################################
#
# Google (Search Engine) Rating Tracking System
# 
# Track domain and keyword page ranks. Analyze data and report
# stats and history.
#
# Multi domain and keyword friendly.
#

#########
# START #
#########
#
#

$month=date("m");
$day=date("d");
$year=date("Y");

$connect = mysql_connect("hostname","user","pass");
@mysql_select_db("Google");

# get domain list
$domains=@mysql_query("SELECT * FROM Domains");
while ($row  =  mysql_fetch_row($domains)) {
$domain="$row[0]";

# get keyword list
$keywords=@mysql_query("SELECT * FROM Keywords");
while ($roz  =  mysql_fetch_row($keywords)) {
$keyword="$roz[0]";

$found="";
$sp="";

# search first 50 pages for keyword
for ($i = 0;;$i = $i + 10) {
    if ($i > 500) {
        break;
    }

     $agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)';
     $mydata=("q=$keyword&hl=en&lr=&safe=off&start=$i&sa=N");
     $host="www.google.com";
     $filename = "/search?$mydata";
     $sp=fsockopen($host,80) or brake;
     socket_set_timeout($sp, 600) or brake;
     fputs($sp,"GET $filename HTTP/1.1\n") or brake;
     fputs($sp,"Host: $host\n");
     fputs($sp,"User-Agent: $agent\n");
     fputs($sp,"Connection: close\n\n");
      while(!feof($sp)) {
         $output .= fgets($sp,128);
         }
     fclose($sp);
     $sp="";

     if(ereg("$domain","$output")){
     $found=1;
     $output="";
       break;
     } else{
     $found=0;
     $output="";}

}

if($found == "1"){
$page = $i / 10;
print "$domain / $keyword - page $page <BR>\n";
} else{
$page = "50";
print "$domain / $keyword - page $page+ <BR>\n";}

flush();

# add to database
mysql_query("INSERT INTO Stats
VALUES('$domain','$keyword','$month','$day','$year','$page')");

# end keywords
}
print "<BR>\n<BR>\n";
# end domains
}

mysql_close($connect);

?>





Thanks for your time and help, I really appreciate it... I am hope it's
just something simple...  :) 

Thanks Allot,

..rick

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to