php+mysql statement timing out

This is a discussion on php+mysql statement timing out within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Ok I'm trying to run a php script written by someone else, not me, and it's getting stuck ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2004
Shabam
 
Posts: n/a
Default php+mysql statement timing out

Ok I'm trying to run a php script written by someone else, not me, and it's
getting stuck in a particular step. Actually it isn't getting stuck per se,
but the browser is, because it's taking forever to return the results back
to the browser.

Here's the line that's responsible for this:

$users = $db->query_return_array("SELECT * FROM user");

It's getting stuck because in my database I have over 60,000 records. Now,
I'm just wanting to get over this step (it's an upgrade script), not looking
for fancy proper methods of php coding.

What alternative ways are there for me to prevent the browser from timing
out? I'm guessing some way of looping through the records, and updating the
client with simple update characters to prevent it from timing out.

Thanks in advance. :)




Reply With Quote
  #2 (permalink)  
Old 03-01-2004
John Smith
 
Posts: n/a
Default Re: php+mysql statement timing out

You could ad limit=10000 to the statement
echo a space
and run the query again and again

But are you sure this is the problem???
How long will it take the SQL server to get the data
The problem is probably somewhere else.

The greatest query I have is only 10.000 records but with severel inner and
left joins and the data gets sorted, this doesn't take more than a second on
my server.
And 6 seconds isn't by far long enough for a browser to time-out


"Shabam" <info@pcconnect.net> schreef in bericht
news:7rSdnVVvSe3p9N7dRVn-gw@adelphia.com...
> Ok I'm trying to run a php script written by someone else, not me, and

it's
> getting stuck in a particular step. Actually it isn't getting stuck per

se,
> but the browser is, because it's taking forever to return the results back
> to the browser.
>
> Here's the line that's responsible for this:
>
> $users = $db->query_return_array("SELECT * FROM user");
>
> It's getting stuck because in my database I have over 60,000 records.

Now,
> I'm just wanting to get over this step (it's an upgrade script), not

looking
> for fancy proper methods of php coding.
>
> What alternative ways are there for me to prevent the browser from timing
> out? I'm guessing some way of looping through the records, and updating

the
> client with simple update characters to prevent it from timing out.
>
> Thanks in advance. :)
>
>
>
>



Reply With Quote
  #3 (permalink)  
Old 03-01-2004
Shabam
 
Posts: n/a
Default Re: php+mysql statement timing out

"John Smith" <someone@nobody.com> wrote in message
news:c1vqgn$cpi$1@news1.tilbu1.nb.home.nl...
> You could ad limit=10000 to the statement
> echo a space
> and run the query again and again
>
> But are you sure this is the problem???
> How long will it take the SQL server to get the data
> The problem is probably somewhere else.
>
> The greatest query I have is only 10.000 records but with severel inner

and
> left joins and the data gets sorted, this doesn't take more than a second

on
> my server.
> And 6 seconds isn't by far long enough for a browser to time-out


I'm not an expert in all of this, but I'm sure it's getting stuck here:

$users = $db->query_return_array("SELECT * FROM user");
$totusers = $db->num_rows();

As for your proposed solution, how would I loop it 10,000 at a time, echo a
space, then requery to get the next 10,000, and then add it to the $users
array? It's vital the end array is the same, as latter code will need it.
Thanks.


Reply With Quote
  #4 (permalink)  
Old 03-01-2004
John Smith
 
Posts: n/a
Default Re: php+mysql statement timing out


"Shabam" <info@pcconnect.net> schreef in bericht
news:ga2dnd1HFvPB7d7dRVn-hw@adelphia.com...
> "John Smith" <someone@nobody.com> wrote in message
> news:c1vqgn$cpi$1@news1.tilbu1.nb.home.nl...
> > You could ad limit=10000 to the statement
> > echo a space
> > and run the query again and again
> >
> > But are you sure this is the problem???
> > How long will it take the SQL server to get the data
> > The problem is probably somewhere else.
> >
> > The greatest query I have is only 10.000 records but with severel inner

> and
> > left joins and the data gets sorted, this doesn't take more than a

second
> on
> > my server.
> > And 6 seconds isn't by far long enough for a browser to time-out

>
> I'm not an expert in all of this, but I'm sure it's getting stuck here:
>
> $users = $db->query_return_array("SELECT * FROM user");
> $totusers = $db->num_rows();
>
> As for your proposed solution, how would I loop it 10,000 at a time, echo

a
> space, then requery to get the next 10,000, and then add it to the $users
> array? It's vital the end array is the same, as latter code will need it.
> Thanks.
>
>

This might do the trick depending on the keys the array returns,
but I think this is some Unique Key from de DB so there should be no
problems with double keys.
I haven't tried it but I think it would work.

//Replace "$users = $db->query_return_array("SELECT * FROM user");" with
this code
echo "<!--";
$limit=100;
$users=array();
$temp_users = $db->query_return_array("SELECT * FROM user limit ".$limit);
while($count($temp_user)<$limit)
{
$users=array_merge($temp_users,$users)
$temp_users = $db->query_return_array("SELECT * FROM user limit ".$limit);
echo " ";
}
$users=array_merge($temp_users,$users)
echo "-->";



Reply With Quote
  #5 (permalink)  
Old 03-01-2004
Shabam
 
Posts: n/a
Default Re: php+mysql statement timing out

> //Replace "$users = $db->query_return_array("SELECT * FROM user");" with
> this code
> echo "<!--";
> $limit=100;
> $users=array();
> $temp_users = $db->query_return_array("SELECT * FROM user limit ".$limit);
> while($count($temp_user)<$limit)
> {
> $users=array_merge($temp_users,$users)
> $temp_users = $db->query_return_array("SELECT * FROM user limit

".$limit);
> echo " ";
> }
> $users=array_merge($temp_users,$users)
> echo "-->";


It doesn't work, even though I cleaned up some of the code errors. The line
"while($count($temp_user)<$limit)" should be
"while(count($temp_users)<$limit)", and even then it returns false on the
very first try because the count = 100 right off the bat.

Help?


Reply With Quote
  #6 (permalink)  
Old 03-02-2004
Doug Hutcheson
 
Posts: n/a
Default Re: php+mysql statement timing out

"Shabam" <info@pcconnect.net> wrote in message
news:DYydnU5DOexoX97dRVn-vw@adelphia.com...
> > //Replace "$users = $db->query_return_array("SELECT * FROM user");" with
> > this code
> > echo "<!--";
> > $limit=100;
> > $users=array();
> > $temp_users = $db->query_return_array("SELECT * FROM user limit

".$limit);
> > while($count($temp_user)<$limit)
> > {
> > $users=array_merge($temp_users,$users)
> > $temp_users = $db->query_return_array("SELECT * FROM user limit

> ".$limit);
> > echo " ";
> > }
> > $users=array_merge($temp_users,$users)
> > echo "-->";

>
> It doesn't work, even though I cleaned up some of the code errors. The

line
> "while($count($temp_user)<$limit)" should be
> "while(count($temp_users)<$limit)", and even then it returns false on the
> very first try because the count = 100 right off the bat.
>
> Help?
>
>


I think you are trying to retrieve $limit records at a time from
your database and merge these into an array. Is that right?

If so, you really want to loop while the number of returned records
is equal to $limit. If the select fails, or returns fewer records,
you have either consumed all records or have hit an error.

I would recode it something like this (warning - aircode):
==========================================
echo "<!--";
$limit=100;
$users=array();
/*
* Set up a loop exit condition
*/
$not_done = true;

/*
* Loop until the condition is met
*/
while($not_done)
{

/*
* Retrieve a chunk of records and collapse gracefully on error
*/
$temp_users = $db->query_return_array("SELECT * FROM user limit
".$limit) or die ("Error retrieving records: ".dberrorblah..);

/*
* Perform the merge
*/
$users=array_merge($temp_users,$users)

/*
* Decide whether we have reached the end of the record set
*/
$not_done = $count($temp_user) == $limit ? true : false;

/*
* Extend our output string by one space
*/
echo " ";
}

echo "-->";
==========================================

Hope it helps.
Kind regards,
Doug

--
Remove the blots from my address to reply


Reply With Quote
  #7 (permalink)  
Old 03-02-2004
John Smith
 
Posts: n/a
Default Re: php+mysql statement timing out


"Doug Hutcheson" <doug.blot.hutcheson@nrm.blot.qld.blot.gov.blot.au > schreef
in bericht news:RCU0c.148$IH5.7935@news.optus.net.au...
> "Shabam" <info@pcconnect.net> wrote in message
> news:DYydnU5DOexoX97dRVn-vw@adelphia.com...
> > > //Replace "$users = $db->query_return_array("SELECT * FROM user");"

with
> > > this code
> > > echo "<!--";
> > > $limit=100;
> > > $users=array();
> > > $temp_users = $db->query_return_array("SELECT * FROM user limit

> ".$limit);
> > > while($count($temp_user)<$limit)
> > > {
> > > $users=array_merge($temp_users,$users)
> > > $temp_users = $db->query_return_array("SELECT * FROM user limit

> > ".$limit);
> > > echo " ";
> > > }
> > > $users=array_merge($temp_users,$users)
> > > echo "-->";

> >
> > It doesn't work, even though I cleaned up some of the code errors. The

> line
> > "while($count($temp_user)<$limit)" should be
> > "while(count($temp_users)<$limit)", and even then it returns false on

the
> > very first try because the count = 100 right off the bat.
> >
> > Help?
> >
> >

>
> I think you are trying to retrieve $limit records at a time from
> your database and merge these into an array. Is that right?
>
> If so, you really want to loop while the number of returned records
> is equal to $limit. If the select fails, or returns fewer records,
> you have either consumed all records or have hit an error.
>
> I would recode it something like this (warning - aircode):
> ==========================================
> echo "<!--";
> $limit=100;
> $users=array();
> /*
> * Set up a loop exit condition
> */
> $not_done = true;
>
> /*
> * Loop until the condition is met
> */
> while($not_done)
> {
>
> /*
> * Retrieve a chunk of records and collapse gracefully on error
> */
> $temp_users = $db->query_return_array("SELECT * FROM user limit
> ".$limit) or die ("Error retrieving records: ".dberrorblah..);
>
> /*
> * Perform the merge
> */
> $users=array_merge($temp_users,$users)
>
> /*
> * Decide whether we have reached the end of the record set
> */
> $not_done = $count($temp_user) == $limit ? true : false;
>
> /*
> * Extend our output string by one space
> */
> echo " ";
> }
>
> echo "-->";
> ==========================================
>
> Hope it helps.
> Kind regards,
> Doug
>
> --
> Remove the blots from my address to reply
>
>

My mistake, I always take the first $limit and not the second $limit with
the second time,
I've changed 3 lines!!!

> > > //Replace "$users = $db->query_return_array("SELECT * FROM user");"

with
> > > this code
> > > echo "<!--";
> > > $limit=100;

$count=0;
> > > $users=array();
> > > $temp_users = $db->query_return_array("SELECT * FROM user limit

> ".$limit);
> > > while($count($temp_user)<$limit)
> > > {
> > > $users=array_merge($temp_users,$users)
> > >$temp_users = $db->query_return_array("SELECT * FROM user limit $count,

".$count+$limit);
$count+=$limit;
> > > echo " ";
> > > }
> > > $users=array_merge($temp_users,$users)
> > > echo "-->";

> >



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:13 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0