0

Not sure if this is going to be possible with PHP but i id it by accident before and i forget how i did it, basically i had made a script that echo'd out a result but i added a u sleep between the three results and it made it so every like 1 second a result would be echo, i need to create a script to echo out a response every 3 seconds. Any tips? Sorry, I'm new to it. When i try the below code it doesn't work.

<?php
echo "test";
sleep(2);
echo "test2";
sleep(2);
echo "test2";
echo $answer;
?> 
Will Econ
  • 11
  • 1

1 Answers1

-1

The output will be buffered until the script ends or you flush() it manually.

<?php
echo "test";
sleep(2);
flush();
echo "test2";
sleep(2);
flush();
echo "next";

When run in cli, this is the best option. When run in browser, check if you're not better off using browser-based technologies like javascript to slowly display parts of the output.

Ralf
  • 355
  • 1
  • 4