Reputation: 408
Many times i run time consuming PHP scripts that echo status updates like 'batch 1 finished', 'batch 2 finished' etc.
i've noticed that sometimes the server responds in a 'live' manner and you can see these status updates as the 'jobs' finish, printed on the browser.
But in other times you have to wait for the script to end, and the browser displays all the status updates at once.
When does the first happen? Is it the browser? Is it PHP setup? The way the script is coded?
Upvotes: 1
Views: 180
Reputation: 20439
You can use ob_flush to send current output to the browser.
Or the process may be run as a background process, and communicate via a fast process, like writing database records, and updated via an AJAX request.
If you have a particular use case, let us know what it is and perhaps someone can advise what would be the best approach for you. (Largely it depends on what sort of server you're running; shared hosts for example often won't run background processes).
Upvotes: 1