Sleep() function with Apache in Windows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Atomus
Forum Newbie
Posts: 1
Joined: Sat May 21, 2005 2:16 pm

Sleep() function with Apache in Windows

Post by Atomus »

Well.. I have a serious problem with sleep() function. I tried to make script which displays one sentence, and the second one after 5 sec delay. Script look like this:

Code: Select all

<?php
echo "It..";
sleep(5);
echo "works?";
?>
The scipt works fine but it displays both sentences at once :(

I tried all kinds of flush(),ob_flush etc. but it didn't help. I heard that's because I am running script on Windows server and sleep() works ok only in Linux. Plz help :(


JCART | PLEASE USE

Code: Select all

TAGS AND REVIEW   [url=http://forums.devnetwork.net/viewtopic.php?t=21171]POSTING CODE IN THE FORUMS[/url][/color]
method_man
Forum Contributor
Posts: 257
Joined: Sat Mar 19, 2005 1:38 am

Post by method_man »

try using the function unsleep()
the number you put in it is micro seconds, that is 1millionth of a second.
if you wanted it to display in 5 seconds you should put

Code: Select all

<?php
echo "It..";
unsleep(5000000);
echo "works?";
?>
hope this helps :D
method_man
Forum Contributor
Posts: 257
Joined: Sat Mar 19, 2005 1:38 am

Post by method_man »

oh also for that to work on windows you need php 5.0
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Method_Man: Why would usleep be any different?

On another,
[url=htt://php.net/sleep]sleep()[/url] user comments wrote:it is a bad idea to use sleep() for delayed output effects as

1) you have to flush() output before you sleep

2) depending on your setup flush() will not work all the way to the browser as the web server might apply buffering of its own or the browser might not render output it thinks not to be complete

netscape for example will only display complete lines and will not show table parts until the </table> tag arrived

so use sleep if you have to wait for events and don't want to burn to much cycles, but don't use it for silly delayed output effects!
Post Reply