0

即使在后台进程完成运行后,我的 PHP 脚本“挂起”也遇到了一个非常奇怪的问题。我正在运行安装了 Tomcat Apache 的 PHP 5.3、Windows Server 2008 R2、IIS7。

项目背景我的脚本通过“shell_exec()”函数生成 PDF 表单。可以生成 1 - 3,000 个表格。生成所有表单后,下载链接和“重新开始”链接应该显示在页面底部 - 相反,该站点继续“加载”并且链接永远不会显示 - 即使我检查了服务器并查看所有文件已完成生成。

此问题仅在生成 300 多个表单时出现,需要 3-6 分钟。

我已将 php.ini 的“max_execution_time”设置为 1200(20 分钟),IIS7 的“连接超时”也设置为 1200 秒。以下是这些设置图片的链接,以确认我已正确设置它们:http: //i49.tinypic.com/15gavew.png -- php.ini http://i49.tinypic.com/9u5j0n.png -- IIS7

我还缺少其他设置吗?是否有我不知道的 Tomcat Apache 连接超时设置?除了“max_execution_time”和“set_time_out”之外,PHP 是否还有另一个“超时”设置?我已经用尽了我的资源,并且不知道为什么我的脚本继续挂起,即使在“while 循环”完成运行并且所有 PDF 都已成功创建之后。

感谢您提供的任何帮助/建议。

While 循环代码

/* 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());
}

}

特定壳线

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);
4

1 回答 1

0

转换了我所有的mysql_ 函数,这些函数现在在 PHP 5.5 中已被弃用,并使用了MySQLi函数。

于 2013-01-30T00:04:35.477 回答