arik arik - 6 months ago 32
PHP Question

PHP output text before sleep

I want PHP to output some text, then sleep for a second and a half, and then output some more text.

<?php

echo 'Output one.';

usleep(1500000);

echo 'Output two.';

?>


My problem is that all text is being put out simultaneously - after having waited those 1.5 seconds. I have read something about a function called flush - but it doesn't seem to work. Maybe I'm not using it write. Any help would be appreciated ^^

Thanks in advance!

Answer

check this out

<?php

ob_start();

echo 'Output one.';
ob_flush();
usleep(1500000);
echo 'Output two.';
ob_flush();

?>