I’m experiencing a very strange problem with my PHP script “hanging” even after the background processes have finished running. I am running PHP 5.3, Windows Server 2008 R2, IIS7 with Tomcat Apache installed.
Project Background My script generates PDF forms through the “shell_exec()” function. Anywhere between 1 – 3,000 forms can be generated. Once all forms have been generated, a download link and “start over” link are supposed to show at the bottom of the page — instead, the site continues to “load” and the links never show up — even when I check the server and see that all files have finished generating.
This issue only comes up when generating 300+ forms, which takes 3-6mins.
I have set my php.ini’s “max_execution_time” to 1200 (20mins), and IIS7’s “Connection Timeout” is also set to 1200 seconds. Here are links to pictures of these settings to confirm I have them set properly:
http://i49.tinypic.com/15gavew.png — php.ini
http://i49.tinypic.com/9u5j0n.png — IIS7
Is there another setting that I am missing? Is there a Tomcat Apache Connection Timeout setting that I am unaware of? Does PHP have another “timeout” setting besides “max_execution_time” and “set_time_out”? I’ve exhausted my resources and have not a clue as to why my script continues to hang, even after the “while loop” has finished running and all PDFs have been successfully created.
Thank you for any and all help/advice.
While Loop Code
/* build zip & directory for PDFs */
$zip = new ZipArchive;
$time = microtime(true);
$new_dir = "c:/pdfgenerator/f-$time";
if(!file_exists($new_dir)) {
mkdir($new_dir);
}
$res = $zip->open("pdf/tmppdf/mf-pdfs_" . $time . ".zip", ZipArchive::CREATE);
$num = 0;
while($row = mysql_fetch_array($result)) {
/* associate a random # assigned to each PDF file name */
$num++;
include($form);
$rand = rand(1,50000);
$file_num = $num * $rand;
$fo = fopen('c:\\pdfgenerator\\f-' . $time . '\\mf_pdf-' . $time . '-' . $file_num . '.html', 'w') or die("can't open file");
fwrite($fo, $output);
echo shell_exec('c:\wkhtmltopdf\wkhtmltoimage c:\\pdfgenerator\\f-' . $time . '\\mf_pdf-' . $time . '-' . $file_num . '.html c:\\pdfgenerator\\f-' . $time . '\\mf_pdf-' . $time . '-' . $file_num . '.jpeg');
/* the follow uses ghost script to execute the ImageMagick convert command from cmd.exe */
$magick_dir = 'C:\imagemagick'; // install IM in short DOS 8.3 compatible path
$send_cmd=$magick_dir .'\convert c:\\pdfgenerator\\f-' . $time . '\\mf_pdf-' . $time . '-' . $file_num . '.jpeg -resize "1710x2200^!" c:\\pdfgenerator\\f-' . $time . '\\mf_pdf-' . $time . '-' . $file_num . '.jpeg' ;
echo shell_exec($send_cmd);
$send_cmd=$magick_dir .'\convert c:\\pdfgenerator\\f-' . $time . '\\mf_pdf-' . $time . '-' . $file_num . '.jpeg c:\\pdfgenerator\\f-' . $time . '\\mf_pdf-' . $time . '-' . $file_num . '.pdf';
echo shell_exec($send_cmd);
/* EO ghostscript code */
/* add the newly generated files to the Zip Archive */
if ($res === TRUE) {
//echo "RESULT TRUE...";
$zip->addFile('c:/pdfgenerator/f-' . $time . '/mf_pdf-' . $time . '-' . $file_num . '.pdf','c:/pdfgenerator/f-' . $time . '/mf_pdf-' . $time . '-' . $file_num . '.pdf');
//echo "FILE ADDED!";
}
}
echo "<h2><a href=\"http://50.63.85.232/med/pdf/tmppdf/mf-pdfs_$time.zip\">Download Zip</a></h2>";
echo "<h2><a href=\"index.php\">Start Over</a></h2>";
$zip->close("pdf/tmppdf/mf-pdfs_" . $time . ".zip", ZipArchive::close());
}
}
Specific Shell Lines
echo shell_exec('c:\wkhtmltopdf\wkhtmltoimage c:\\pdfgenerator\\f-' . $time . '\\mf_pdf-' . $time . '-' . $file_num . '.html c:\\pdfgenerator\\f-' . $time . '\\mf_pdf-' . $time . '-' . $file_num . '.jpeg');
/* the follow uses ghost script to execute the ImageMagick convert command from cmd.exe */
$magick_dir = 'C:\imagemagick'; // install IM in short DOS 8.3 compatible path
$send_cmd=$magick_dir .'\convert c:\\pdfgenerator\\f-' . $time . '\\mf_pdf-' . $time . '-' . $file_num . '.jpeg -resize "1710x2200^!" c:\\pdfgenerator\\f-' . $time . '\\mf_pdf-' . $time . '-' . $file_num . '.jpeg' ;
echo shell_exec($send_cmd);
$send_cmd=$magick_dir .'\convert c:\\pdfgenerator\\f-' . $time . '\\mf_pdf-' . $time . '-' . $file_num . '.jpeg c:\\pdfgenerator\\f-' . $time . '\\mf_pdf-' . $time . '-' . $file_num . '.pdf';
echo shell_exec($send_cmd);
converted all of my mysql_ functions, which are now deprecaded as of PHP 5.5, and utilized MySQLi functions.