Echo messages while php script still executes

前端 未结 9 1051
轻奢々
轻奢々 2021-02-08 13:05

I have a php script that uses cURL and takes about 10-15 minutes to execute. What it does, it parses about 1000 pages looking for specific matches and throughout the script I ha

相关标签:
9条回答
  • 2021-02-08 13:48

    I'm using the @ob_flush() after every echo. In this example PHP_EOL creates a new line after $string

    function output($string){
        echo $string.PHP_EOL;
        @ob_flush();
    }
    
    0 讨论(0)
  • 2021-02-08 13:50

    Use flush to immediately send output to the browser, by flushing the output buffer.

    echo "foo";
    flush();
    echo "bar";
    flush();
    
    0 讨论(0)
  • 2021-02-08 13:51

    Basically, have your script write HTML output to a temporary log file. Then use ajax to periodically update the end-user's browser with the temporary log file. jQuery will make quick work of this.

    Ajax is the only guaranteed way to get it to work on all browsers. Here is a quote from PHP's flush page.

    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.

    0 讨论(0)
提交回复
热议问题