PHP + MySql timing out in my browser

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shabam

    PHP + MySql timing out in my browser

    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_a rray("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. :)



  • Shawn Wilson

    #2
    Re: PHP + MySql timing out in my browser

    Shabam wrote:[color=blue]
    >
    > 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_a rray("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.[/color]

    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@glassgian t.com

    Comment

    • Shabam

      #3
      Re: PHP + MySql timing out in my browser

      > You could try ob_flush, but if it's just that one line that takes forever,
      it[color=blue]
      > won't work. If you have multiple lines like that one, you could output a[/color]
      bit of[color=blue]
      > text to the browser between each one.
      >
      > Without seeing the rest of your code, your best bet might be to[/color]
      reconsider:[color=blue]
      > -do you need all the fields (*), or do you just need the userid and signup[/color]
      date[color=blue]
      > (or whatever)?
      > -do you need all 60,000 records? Could you narrow it down with a WHERE[/color]
      clause?[color=blue]
      > -could you split this up into multiple requests and have a cron job run[/color]
      it?[color=blue]
      > -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[/color]
      if[color=blue]
      > I'm wrong), and likely reflects bad script design. If each user record[/color]
      averages[color=blue]
      > 100 bytes then you've got a ~6Mb array.[/color]

      Thanks for the advice. However the problem is that it's a third-party
      script used to upgrade a previous version of the software to the latest
      version. It basically involves taking the data out, creating a new
      database, and then dumping it back in. I didn't mention the other lines of
      code because #1, the upgrade script only needs to work once.

      So, basically I'm looking for another way to perform the same function of
      this code:

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

      Thanks!


      Comment

      • Shawn Wilson

        #4
        Re: PHP + MySql timing out in my browser

        Shabam wrote:[color=blue]
        >[color=green]
        > > You could try ob_flush, but if it's just that one line that takes forever,[/color]
        > it[color=green]
        > > won't work. If you have multiple lines like that one, you could output a[/color]
        > bit of[color=green]
        > > text to the browser between each one.
        > >
        > > Without seeing the rest of your code, your best bet might be to[/color]
        > reconsider:[color=green]
        > > -do you need all the fields (*), or do you just need the userid and signup[/color]
        > date[color=green]
        > > (or whatever)?
        > > -do you need all 60,000 records? Could you narrow it down with a WHERE[/color]
        > clause?[color=green]
        > > -could you split this up into multiple requests and have a cron job run[/color]
        > it?[color=green]
        > > -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[/color]
        > if[color=green]
        > > I'm wrong), and likely reflects bad script design. If each user record[/color]
        > averages[color=green]
        > > 100 bytes then you've got a ~6Mb array.[/color]
        >
        > Thanks for the advice. However the problem is that it's a third-party
        > script used to upgrade a previous version of the software to the latest
        > version. It basically involves taking the data out, creating a new
        > database, and then dumping it back in. I didn't mention the other lines of
        > code because #1, the upgrade script only needs to work once.
        >
        > So, basically I'm looking for another way to perform the same function of
        > this code:
        >
        > $users = $db->query_return_a rray("SELECT * FROM user");
        > $totusers = $db->num_rows();[/color]

        Ah, then it's likely $users is used for more than just determining the total
        number of users. But if you're sure that's all it's used for, I'm not sure how
        to do that using whatever classes you're using, but you could probably use
        mysql_connect, mysql_query() and count.



        Regards,
        Shawn


        --
        Shawn Wilson
        shawn@glassgian t.com

        Comment

        • Chung Leong

          #5
          Re: PHP + MySql timing out in my browser


          Uzytkownik "Shabam" <info@pcconnect .net> napisal w wiadomosci
          news:Vrednb8phJ Lv597d4p2dnA@ad elphia.com...[color=blue]
          > Thanks for the advice. However the problem is that it's a third-party
          > script used to upgrade a previous version of the software to the latest
          > version. It basically involves taking the data out, creating a new
          > database, and then dumping it back in. I didn't mention the other lines[/color]
          of[color=blue]
          > code because #1, the upgrade script only needs to work once.
          >
          > So, basically I'm looking for another way to perform the same function of
          > this code:
          >
          > $users = $db->query_return_a rray("SELECT * FROM user");
          > $totusers = $db->num_rows();[/color]

          You'll have to retrieve the data in chunks, while every now and then output
          something to the browser.

          for($i = 1; $users = $db->query_return_a rray("SELECT * FROM user LIMIT $i,
          50"); $i+=50) {
          // insert the users
          echo "<!-- GARBAGE FOR IE'S CONSUMPTION -->\n";
          }

          Be sure to use set_time_limit( ) to 0 to prevent PHP from timing out


          Comment

          Working...