5
Does anyone know a way to monitor PHP code processing and present to the client?
I’m designing a converter layout which takes data files in a given format and converts to another format.
Basically, I would like to present to the user (in the client browser), a progress bar with the evolution of the processing of the files on the server. This processing is not the progress of the upload (that I do with XMLHTTPRequest
), but the progress of the conversion.
I’ve tried setting a cookie with setcookie
and setrawcookie
in PHP every 10% processed and trying to get the value of cookie with Javascript on the client side, also every 1 second with setInterval()
, but it seems that PHP sends all cookies once after processing the script, and not at a time when setcookie()
is called.
I also tried to use header()
instead of setcookie
and also the header sent only appear in the client after the complete processing of script.
The start of the server processing I have done with XMLHTTPRequest
to the page that does the processing.
I also tried with iframe, running the processing in iframe and trying to get cookies from it on the main page, but I was unsuccessful. I was able to monitor using a text file where php records progress and I read it through Ajax. However, it seems to only work with php safe thred
You can display a PHP service that returns only progress. Your client would access the URL to fetch the value.
– RSinohara
Like this: the php script that does the conversion keeps saving the progress in a database or file on the server. The client keeps making requests for another script that keeps reading the progress of this database/ file?
– Everton da Rosa
I like to use Gearman for those things. http://br1.php.net/manual/en/gearmanclient.addtaskstatus.php
– Marcos Regis
I didn’t. It also has this technique: http://rberaldo.com.br/server-push-long-polling-php-ios/
– Everton da Rosa