Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems

Posted by SeanC (SeanC), 8 November 2004
I'm writing a script using a while statement which needs to pause for 45 seconds everytime it's been through the loop - is this possible in PHP and if so what command do I need to use.



Posted by admin (Graham Ellis), 9 November 2004
It's possible but you're very likely going to end up solving your immediate question and raising others.

The sleep function in PHP delays program execution for a given number of seconds:
is the straightforward answer to your question

BUT ...

a) Buffering.  If your script is buffering its output, then information written to the buffer will NOT be flushed out (automatically) when you get to the sleep. In other words, if you have a while loop that sleep 5 times 45 seconds, you may not see any output at all for 225 seconds

b) Timeouts. Your script will have limited execution time, and your user's browsers may give up after a certain period.

I have personally used sleep to pause a script for a couple of seconds between reading from other URLs internally (to avoid any hint of being accused of making a denial of service attack), and to ensure that buffers are flushed / files written before kicking off something that reads files I've just written. It's also useful in standalone PHP programs.

Sean, I'm *not* saying that you shouldn't use sleep - I would need a wider view that your question gives - but *if* you're generating multiple pages from a single script then you should consider structuring your script to use a refresh metatag and genarate a completely new page each time.
        <meta http-equiv="Refresh" content="10; ">

We have an example using this 10 second pause at  This example is really for use on our inhouse network though; the graphics are huge (they rescale to fit the window so must be ultra high res) and you'll need a good "very" broadband connection for it to be effective. It's a "dream" on our 3 Mbit link.

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: • WEB: • SKYPE: wellho