Using the PHP Output Buffer to Issue JavaScript During Processing
source link: https://www.codesd.com/item/using-the-php-output-buffer-to-issue-javascript-during-processing.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Using the PHP Output Buffer to Issue JavaScript During Processing
I have some PHP code that is receiving and processing large images. I'd like to echo out some JavaScript at certain points while the image is being processed to update the DOM with jQuery. Here is some sample code, but it isn't working. It just waits the entire 5 seconds and then makes the alerts happen back to back. I want it to do the first alert immediately and then next alert after 5 seconds.
ob_start();
echo '<script type="text/javascript">alert(\'1...\');</script>';
ob_flush();
sleep(5);
ob_start();
echo '<script type="text/javascript">alert(\'2...\');</script>';
ob_flush();
Can anyone help?
Most browsers buffer content until a certain size is reached. Try making your script blocks longer by padding them with something.
Also: You should call flush, not just ob_flush, and make sure zlib compression is turned off.
Related Articles
How does the php output buffer work (problem using $ _SERVER ['REQUEST_TIME'] to calculate script execution time)
Stop the PHP output buffer
to use the html5 output tag to display javascript variables?
Is it better to view the latest tweets on a web page using the PHP API or Javascript?
Stacking PHP Output Buffer
add text content with jquery using the php variable
Using the asset pipeline to include a javascript file in the rails 4 project
Dynamic tabs with the R-Shiny application using the same output function
strategy to divide the php output into smaller outputs (ajax, php) (nested ajax calls, ajax in ajax?)
Should I use a PHP extension for ImageMagick or simply use the PHP Exec () function to execute the terminal commands?
Why disable the standard output buffer during multithreading?
How to access the php variable from my external javascript file
How to use the PHP interactive wrapper
using the phps exec command to launch an application on the server
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK