logo

php echo without waiting to finish execution

php echo without waiting finish execution

most of the time we get into some task which require longer than normal to complete execution due to long execution time it is hard to echo output instantly before the completion of execution, Normally when we write echo inside loop it echos it out after full page execution gets done. which does not look good when we are debugging or giving notification to end user and updating which specific task is currently running, Here I will show you how in php echo without waiting to finish execution completely.

we just need 2 extra line to put at before loop or where we are echoing out the output, these line are

If we have too heavy script taking longer than default allowed time_limit and memory size we can also extend it by the following 2 lines

To understand how this works just follow me and copy paste the following codes, when you try yourself and see the difference in result you will understand and will need less attention to descriptions over here.

lets take a look at the following example, the following code will output all at once after completion of whole code execution.

And now try the following code and glance at result it will show output at each iteration of loop do not waiting to complete the execution.

We can also write multiple loops to display instant result without waiting for completing the execution of whole script.

Hope this helped you, let me know if you have better and optimized solution for such cases. I will be using this in all my upcoming projects and scripts as it is good to have instant output and get updated of script execution this will also help catching the bug easily wasting

Comments

    Write a Reply or Comment

    Your email address will not be published. Required fields are marked *