0

I am trying to run a script that is more intensive and long waiting so want to be able to make it real time, but for some reason is not working. Script is located live here: https://newskillsacademy.co.uk/info.php and the PHP info here https://newskillsacademy.co.uk/info.php?info. What am I doing rong. Tested all kinds of real-time rendering scripts and they are not working on this server but on my localhost is ok. Same PHP version.

<?php
    for ($i = 1; $i <= 10; $i++)
    {
       echo '<p>' . $i . '</p>';
       flush();
       sleep(1);
    }
?>
Adrian
  • 2,273
  • 4
  • 38
  • 78
  • From the [manual](http://php.net/manual/en/function.flush.php): *flush() may not be able to override the buffering scheme of your web server and it has no effect on any client-side buffering in the browser. It also doesn't affect PHP's userspace output buffering mechanism. This means you will have to call both ob_flush() and flush() to flush the ob output buffers if you are using those.* Overall you need to rethink your strategy. – apokryfos Aug 12 '17 at 05:59
  • @apokryfos Just added `ob_flush` after `flush` and same thing. – Adrian Aug 12 '17 at 06:01
  • Tested also like this: https://stackoverflow.com/questions/4481235/php-flush-ob-flush-not-working?rq=1 and still nothing https://newskillsacademy.co.uk/info.php?ex2 – Adrian Aug 12 '17 at 06:02
  • Yet another reason to rethink your strategy. Basically you can add some front-end javascript and split the back-end task into smaller ones. Start the task with a javascript call, when the result comes in call the next task (the result of the first task can contain a URL for the next task to perform). It's more reliable this way. – apokryfos Aug 12 '17 at 06:09
  • @apokryfos. Understood but I want to keep it simple, only php. Tried also http://www.binarytides.com/php-output-content-browser-realtime-buffering/ over here https://newskillsacademy.co.uk/info.php?ex3. Same results for all.I know it's possible only with php as on my localhost it works without issues, and i don't use any javascript / websocket... – Adrian Aug 12 '17 at 06:12
  • Based on the manual it sometimes is out of your control on whether this would work on not depending on your hosting server. – apokryfos Aug 12 '17 at 06:17

0 Answers0