I want to implement a PDF-exportfunction with PHP on a virtual LAMP-server. The user clicks on a link to a PHP-script that produces the PDF with wkhtmltopdf. This PDF can be more than a thousand sites long and needs very many SQL-queries and images. So it can take several minutes to produce this PDF.
The thing is, that most browsers will timeout after a certain time when the server dont respond anything. In firefox this will happen after 300 seconds by default. In about:config it is defined by network.http.response.timeout. When I change the value to 100 , the browser will timeout after 100 seconds when using the pdf-export. The solution would be some kind of heartbeat to avoid a timeout in the browser. I want to realize this heartbeat with the PHP flush() functions but I just cant get it to work.
Here is a testcode. It is from http://manzzup.blogspot.de/2013/11/real-time-updating-of-php-output-using.html:
// Turn off output buffering
ini_set('output_buffering', 'off');
// Turn off PHP output compression
ini_set('zlib.output_compression', false);
//Flush (send) the output buffer and turn off output buffering
while (@ob_end_flush());
// Implicitly flush the buffer(s)
ini_set('implicit_flush', true);
ob_implicit_flush(true);
echo "add this";
echo str_pad("padding: ",8000,"_");
echo "<br />";
ob_flush();
flush();
sleep(5);
echo "Program Output";
ob_flush();
flush();
This is just the last example I have tested, but I am new on stackoverflow and cant post more then 2 Links. here is another related site:
http://www.stevesouders.com/blog/2013/01/31/http-archive-adding-flush/
Is it possible to use the flush() functions in all browsers? Does someone have a running site that uses this functions? What server configurations can stop the flush() functions from working?
Thank you for all upcoming answers!
As you can read here: http://nl1.php.net/flush , avoid using flush()
inside a <table>
and give a newline within each flush. Also you need to disable output buffering and compression, but you already did this.
Don't forget to increase or disable the time allowed for the script to run. This needs to be done in PHP.ini (sometimes this can even be done runtime), but the web server also has settings for this.
edit Try also adding header( 'Content-type: text/html; charset=utf-8' );
.
Increase script execution time limit ini_set('max_execution_time', time in seconds);