Re: PHP + MySql timing out in my browser

From: Shawn Wilson (shawn_at_glassgiant.com)
Date: 03/01/04


Date: Mon, 01 Mar 2004 13:53:15 -0400

Shabam wrote:
>
> 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.

You could try ob_flush, but if it's just that one line that takes forever, it
won't work. If you have multiple lines like that one, you could output a bit of
text to the browser between each one.

Without seeing the rest of your code, your best bet might be to reconsider:
-do you need all the fields (*), or do you just need the userid and signup date
(or whatever)?
-do you need all 60,000 records? Could you narrow it down with a WHERE clause?
-could you split this up into multiple requests and have a cron job run it?
-could you delete some of those 60,000 records (get rid of the dead wood)?

A 60,000 element array is pretty unusual, I think (someone will correct me if
I'm wrong), and likely reflects bad script design. If each user record averages
100 bytes then you've got a ~6Mb array.

Regards,
Shawn

-- 
Shawn Wilson
shawn@glassgiant.com
http://www.glassgiant.com


Relevant Pages

  • Re: Which Is The Better Approach To Working With Javascript?
    ... implementation has no interprocess communication capability, or ability to interface with a script interpreter. ... Java SCRIPT runs in the browser exclusively. ... No language is written just for a single environment. ...
    (comp.lang.php)
  • Controling Modal Dialogs
    ... In order to trap new windows created by script calls to window.open, ... Form and a new browser control in that tab. ... window.external.showModalDialog(dialog, varArgIn, varOptions);} ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Re: how to run scripts after a page has already loaded and been sent to a users browser?
    ... > It's because PHP is a server side scripting language, ... > do stuff before you send stuff to user's web browser. ... As we've discussed on this newsgroup before, if a script starts ... that is after the last HTML is sent to a web browser. ...
    (alt.php)
  • Re: Problems with PrintReady javascript and published Frontpage 2003 web site
    ... 2003 web site ... > In your script delete the 5 lines you have added between ... > Then Test in Browser before you publsih ... > | link it opens a new windows and my browser freezes. ...
    (microsoft.public.frontpage.client)
  • Re: Development with IE 7 for non-Windows users.
    ... standards that most other browsers accept, I rely only on the standards. ... It is only the rendering engine itself that is to blame. ... Sometimes script can be very useful. ... Obviously, if a users browser ...
    (microsoft.public.windows.inetexplorer.ie6.browser)