Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: How can I output HTML while the script is still running?

Tags:

loops

foreach

php

I have a script that checks the status of a few hundred webpages. However, the script takes about 2 minutes to load, and the screen is blank until the script has finished running. Then all the data is outputted at once.

I want to output data while the script is still running. Here's part of my script:

foreach ($urls as $url){

    $headers = get_headers($url,true);
    $status = $headers[0];
    list($protocol, $code, $message) = explode(' ',$status,3);

    echo '<br>'.$url.'<br>'.$code.'<br>';

} 
like image 801
Linksku Avatar asked Mar 07 '26 14:03

Linksku


1 Answers

http://php.net/manual/en/function.flush.php contains the answer you seek.

Be aware this may negatively hit your performance, but it sounds like you're more interested in seeing it's progress. :-)

like image 161
Caladain Avatar answered Mar 09 '26 04:03

Caladain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!