Page 1 of 1

Query crashes when table contains 200 odd entries

Posted: Thu May 07, 2009 10:40 pm
by vivekkimi

Code: Select all

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!*/

Re: HELP ME!!

Posted: Thu May 07, 2009 10:46 pm
by Christopher
It would help if you had put your code in

Code: Select all

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!!!" ...

Re: HELP ME!!

Posted: Thu May 07, 2009 10:50 pm
by mickd
I'm surprised it was running in the first place!

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.

Re: HELP ME!!

Posted: Thu May 07, 2009 10:57 pm
by vivekkimi
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.

Re: HELP ME!!

Posted: Thu May 07, 2009 11:20 pm
by mickd
When you said it crashes, does it just timeout?

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.

Re: HELP ME!!

Posted: Thu May 07, 2009 11:24 pm
by Benjamin
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.

Re: Query crashes when table contains 200 odd entries

Posted: Fri May 08, 2009 12:22 am
by vivekkimi
im really sorry.....im new to this