4

Using the PHP Output Buffer to Issue JavaScript During Processing

 3 years ago
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.
neoserver,ios ssh client

Using the PHP Output Buffer to Issue JavaScript During Processing

advertisements

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)

i really didnt know how to word the title so i did the best i could. we have an issue where we calculate final script (web based) execution time. we do a simple if(time()-$_SERVER['REQUEST_TIME']>X){ logMe(); } we find that sometimes the script is sh

Stop the PHP output buffer

I need to display continuous output from my php script. The script will stay in a loop of printing log data from a device and sleeping. My problem is that I can't get PHP or Apache to output data before the script is completed. I have tried all the c

to use the html5 output tag to display javascript variables?

Sorry if this is a silly question, but I've been trying to use AJAX to display my javascript variables in 'real time' with little luck. I'm definitely a beginner though so this could be the problem haha- When I see the AJAX code, it always seems to r

Is it better to view the latest tweets on a web page using the PHP API or Javascript?

I want to display a user's latest Tweets on a webpage while maintaining the ability to style the Tweets with custom CSS and also maintaining good page load speed. I have managed to display the latest Tweets in 2 ways. Using the PHP Twitter library (b

Stacking PHP Output Buffer

The following is not achieving what I desire <? echo ob_start() . "<br>"; echo "1x<br>"; echo ob_start() . "<br>"; echo "2x<br>"; echo ob_flush() . "<br>"; echo "3x<

add text content with jquery using the php variable

Possible Duplicate: Pass a PHP string to a Javascript variable (including escaping newlines) Hy, so my problem is that i have a textarea which is generated with jquery, like this: $var input = $('<textarea name="somename"></textarea>

Using the asset pipeline to include a javascript file in the rails 4 project

I added a simple Javascript file to my rails project beer_background.js and put the file in app/assets/javascripts I want to load the beer_background.js when the application.html.erb is rendered, so I put the following line in the application.html.er

Dynamic tabs with the R-Shiny application using the same output function

Goal: I'm working on a bioinformatics project. I'm currently trying to implement R code that dynamically creates tabPanels (they are essentially carbon copies except for the data output). Implementation: After doing some research I implemented this s

strategy to divide the php output into smaller outputs (ajax, php) (nested ajax calls, ajax in ajax?)

I don't know the correct terminology to search for the solution. Please suggest a strategy to break up the php output into small chunks and pass them stepwise to ajax's responseText. The project is an ajax webpage that takes a text string (lastname)

Should I use a PHP extension for ImageMagick or simply use the PHP Exec () function to execute the terminal commands?

I need to do the following image manipulations for images uploaded by users on my site: Resize images (if greater than a certain dimension) Convert all image formats to jpg's Add a watermark to the bottom of all images Do I need to use either the Mag

Why disable the standard output buffer during multithreading?

I'm trying to learn on multithreading, and I have a simple question. On most of the examples I find, the standard output buffer is turned off before letting multiple threads to use it with: setbuf(stdout,NULL); Why? Codes print the same if I remove t

How to access the php variable from my external javascript file

How to access the php variable from my external javascript file. this is my getting.js file $(function(){ $(".search").keyup(function() { var searchid = $(this).val(); var dataString = 'search='+ searchid; if(searchid!='') { $.ajax({ type: "

How to use the PHP interactive wrapper

I'm using Ubuntu 12.04 64 bit and I want to use the PHP interactive shell: php -a But it doesn't seem to work very well, a lot of syntax is incorrectly interpreted. When I run php -a it displays: interactive mode enabled And just a cursor blinking. I

using the phps exec command to launch an application on the server

I'm attempting to run an application on the server, invoking it from PHP using the following code. $application = "D:\\Program Files (x86)\\ScanBoy\\DM ScanBoy.exe"; exec($application); Right now the application is 'run' however it crashes insta

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK