RE: flushing AJAX scripts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Some browser would like to receive at list N characters (bytes) even if
you force the flush, before the browser will show those characters.
In
any case, the Ajax request will not be completed until its readyState
will be 4, which means the page execution on the server has finished
(released, php has gone, flush or not flush)
For a task like this one you have few options:
 1 - launch  new thread if your host is able to do it
 2 - use a Comet like response (for php I wrote Phico some while ago)
In any case, I hope this stressful operation cannot be performed from thousand of users or you can say bye bye to the service.
Alternatives:
 1 - optimize your database
 2 - delegate the job once a time rather than every click (cronjob)
 3 - if the bottleneck is PHP, create an extension in C to perform the same task

Hope this help.

Regards

P.S.
Internet Explorer a part, you can read the responseText on readystate 3
which will be called different time (most likely for each flush).
If IE is not your target, you could consider this opportunity to read the sent stream so far.

> Date: Fri, 27 Mar 2009 08:49:35 +1100
> From: dmagick@xxxxxxxxx
> To: jbw2003@xxxxxxxxxxxxx
> CC: php-general@xxxxxxxxxxxxx
> Subject: Re:  flushing AJAX scripts
> 
> jim white wrote:
> > I am using jQuery AJAX request to run a script that can take several 
> > minutes to create a report. I want to start the script and immediately 
> > echo a response to close the connection and then let the script complete 
> > a report which I can get later. I have tried several thing such as
> > 
> > ob_start();
> > echo json_encode(array("time"=>$now, "message"=>"Report has started 
> > running!"));
> > ob_end_flush();
> 
> Try something like this
> 
> echo "something";
> flush();
> 
> without the ob* stuff.
> 
> -- 
> Postgresql & php tutorials
> http://www.designmagick.com/
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/windows/windowslive/products/photos.aspx

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux