Solved

Timing on a loop..

Posted on 2008-10-01
3
208 Views
Last Modified: 2008-10-02
$result = mysql_query($query);
echo mysql_error();
 while($row = mysql_fetch_array($result)){
        $search = $row[0];
        echo $search;

I have this.  The final result will be different but I will be able to illustrate my question.   I want to loop the results one by one, one every 15 second and then the next row.  What would be the best way to do this?  For the end result I'll strictly be doing stuff that doesn't display on the screen but I'm not sure what the consequences are of running a loop with potentially thousands of records in a database.

.. Is it even possible to add timing to a php while loop..
0
Comment
Question by:cstormer
  • 2
3 Comments
 
LVL 27

Expert Comment

by:yodercm
ID: 22621012
$result = mysql_query($query);
echo mysql_error();
 while($row = mysql_fetch_array($result)){
        $search = $row[0];
        echo $search;
        sleep(15);
}
0
 

Author Comment

by:cstormer
ID: 22621161
This does work, when it's finish with the whole query it displays.

What are the concequences of running this against a few thousand records?
0
 
LVL 27

Accepted Solution

by:
yodercm earned 500 total points
ID: 22623120
It will take a few thousand x 15 seconds to run the script.  The query is done only only once, so the time is not of consequence to the database.  However, you may need to set your php time limit to ensure the program continues running.

set_time_limit(150000);

You may also need to check with your webhost or the server settings to ensure that this will work.  I'm not personally familiar with how the time limits are enforced.
0

Featured Post

How our DevOps Team Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question