Query crashes when table contains 200 odd entries

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!

Moderator: General Moderators

Post Reply
vivekkimi
Forum Newbie
Posts: 3
Joined: Thu May 07, 2009 10:37 pm

Query crashes when table contains 200 odd entries

Post 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!*/
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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: HELP ME!!

Post 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!!!" ...
(#10850)
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Re: HELP ME!!

Post 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.
vivekkimi
Forum Newbie
Posts: 3
Joined: Thu May 07, 2009 10:37 pm

Re: HELP ME!!

Post 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.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Re: HELP ME!!

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: HELP ME!!

Post 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.
vivekkimi
Forum Newbie
Posts: 3
Joined: Thu May 07, 2009 10:37 pm

Re: Query crashes when table contains 200 odd entries

Post by vivekkimi »

im really sorry.....im new to this
Post Reply