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
For 2023 - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))

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., 2023: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho