Echo messages while php script still executes

前端 未结 9 1056
轻奢々
轻奢々 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:37

    So, this is a old post but I found a solution for this. As I also have to make the same thing, output when the script is still running. Not any answer from here helped. First of all, I am using Win32 server(production) and XAMPP as local for tests. This example is just a proof of concept and can be modified as you please.

    ";
    for($k = 0; $k < 40000; $k++) echo ' ';
    sleep(1);
    }
    ?>
    

    So, we open output buffer as implicit. Then we make a demo loop to count from 1 to 10 and display the values as they are been processed. Second loop will fill in the browsers buffer. And finally to check if everything is working well we make a sleep for 1 second. Otherwise the script will run too fast and we could not know if we achieved the goal. Hope this helps !

提交回复
热议问题