PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
mysql_connect( "localhost" , "zzz", "zzz");
mysql_select_ db("crawl" ); // database name
$hosts=mysql_ query("select * from xyz where =0;");
while($row=mysql_ fetch_array( $hosts))
{
$url=$row["name" ];
$c=get_keywords( "$url");
if(strlen($c) ==0)
$c="No Keywords";
mysql_query( "update xyz set keywords= \"$c\" where name='$url' ;");
mysql_query( "update xyz set kflag=true where name='$url';");
echo "done";
}
/*
xyz is a table full of urls..i want to update this table by adding keywords of each page to the corresponding url. get_keywords is a func to extract keywords for a given url.
kflag is used to detect if the keywords have been searched for..for the particular url.
this code works fine when the table has very few entries say 4-8 but crashes when table contains 200 odd entries.
i'm stuck here big time..i probably need to use multi threading but i'm not able to figure out how..
CODE RED!!! please help!*/
Last edited by Benjamin on Thu May 07, 2009 11:25 pm, edited 1 time in total.
Reason:Changed subject from HELP ME to something more descriptive.
tags (I fixed it). And writing a descriptive title for you post will let people who might know the answer what the post is about. And then there is the use of "CODE RED!!!" ...
But as a starter you could remove the spaces from these function names (it shouldn't have a space)
mysql_select_ db
mysql_ query
mysql_ fetch_array
Those functions should just be 1 word each.
Also, remove the ; from inside your query strings.
Yes i removed all the spaces...and as u said i made some changes to the script...but problem remains.
i think the problem is tat get_keywords func is taking more time to return the result...hence it will work for first few entries in the database not for all. so is there any mechanism to ensure that the while loop waits until the func keywords returns.
i tried using sleep but it halted the execution completely.
It probably does have something to do with your get_keywords function. Though PHP parses the code linearly, so it wouldn't say, start parsing other stuff if 1 function is slow. It would finish that function, return it, then continue.
It maybe has something to do with the url that you are trying to process. The script might be timing out/getting no response from the url page. Maybe post some code for get_keywords, and someone else might know why, I'm not sure how much help I'll be from this point on. I'll still of course try to help if i can.
Forum Rules 1 1.1 2 wrote:
Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.