Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

PHP's flush() causing HTML to disappear for the time the script is running

Hello everybody!

I am currently facing a little problem with my project I am working on.

I have a php script which looks like this:

PHP Code

<?php 
echo '<li class="list-group-item list-group-item-info">Starting to gather data!</li>';
      
ob_flush();
      
flush();
      
$url = $unsplash;
      
$cmd = $unsplash . ' - ' . $amount;
      
exec($cmd);
      echo 
'<li class="list-group-item list-group-item-success">Gathering Data Completed</li>';
      
ob_end_flush(); 

I narrowed the problem down to the flushes I have, as the problem does no occur when deleting those flushes - but then I dont get my echos immediatly as I need them.

So the thing is, that any kind of code I am putting below this php script (which is in the middle of my website) is being "deleted" for the time of the code running. After the code finishes the website looks normal again and the HTML content below my script "reappears". Also what I found out is, that my developer tools in chrome are empty when I try to analyze my HTML - it is just blank.

Thank you for your time
Quote:Several servers, especially on Win32, will still buffer the output from your script until it terminates before transmitting the results to the browser.

Even the browser may buffer its input before displaying it. Netscape, for example, buffers text until it receives an end-of-line or the beginning of a tag, and it won't render tables until the </table> tag of the outermost table is seen.

Check out the PHP Manual.
http://php.net/manual/en/function.flush.php

Edit: You could use some javascript to blur out the whole page and a loading image to appear in the center while the script finishes running. (If you want to get around it)
(Sep 28, 2016 10:58 AM)Prof. Farnsworth Wrote:  Check out the PHP Manual.


Edit: You could use some javascript to blur out the whole page and a loading image to appear in the center while the script finishes running. (If you want to get around it)

I knew about the closing tag thingy. Unfortunately that is not the case with my code. :/

The second thing on the other hand is something to consider, thanks :)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Javascript]  by flexing_99Apr 29, 2023 12:02 AM 3 270 Apr 29, 2023 12:02 AM
Last Post: Zgh600
[PHP] by moe2kJan 3, 2022 11:04 AM 13 518 Jan 3, 2022 11:04 AM
Last Post: Hackers
[Javascript]  by flexing_99Jul 4, 2020 04:11 PM 0 132 Jul 4, 2020 04:11 PM
Last Post: flexing_99