Php 如何关闭exec()函数命令或关闭exec()函数运行的命令?
如何关闭此命令,因为它显示“过度资源使用:”错误。我遇到了wkhtmltopdf无限期挂起的问题,因此我使用实用程序运行它,该实用程序允许您设置执行时间限制Php 如何关闭exec()函数命令或关闭exec()函数运行的命令?,php,command,exec,wkhtmltopdf,Php,Command,Exec,Wkhtmltopdf,如何关闭此命令,因为它显示“过度资源使用:”错误。我遇到了wkhtmltopdf无限期挂起的问题,因此我使用实用程序运行它,该实用程序允许您设置执行时间限制 $cmd_pdf = 'xvfb-run --wait=0******************'; exec($cmd_pdf, $output_pdf); 你好,罗布,我用了超时,但没有工作$timoutTime='120s'$cmd_pdf='xvfb run--wait=0 timeout'.$timoutTime.'wkhtmlt
$cmd_pdf = 'xvfb-run --wait=0******************';
exec($cmd_pdf, $output_pdf);
你好,罗布,我用了超时,但没有工作$timoutTime='120s'$cmd_pdf='xvfb run--wait=0 timeout'.$timoutTime.'wkhtmltopf-b0-l0-r0-t0-q--页面高度'$页高。”--页宽'$页宽-是A4’。basename($html_文件)。“”。basename($pdf_文件);exec($cmd\u pdf,$output\u pdf);timeout是一个包装其他命令的命令,因此它必须是链中的第一个命令。看一下文档。
<?
$htmlFilePath = 'myfile.html';
$pdfFilePath = 'myfile.pdf';
/*
* Current version of wkhtmltopdf has some deep down nasty bug that causes it to hang
* indefinitely at random on linux. Let's add some retry logic to work around that.
*/
$output = array();
$timeoutStatusCode = 124;//Timeout utility will return 124 as the exit code if it does in fact time out
$timoutTime = '15s'; //In prod, most PDFs seem to take < 1.5 seconds, but let's be generous.
$exitStatus = null;
$maxIterations = 15; //I've seen nine in a row fail, mostly only takes one retry
$currIteration = 0;
$shellArgs = '--use-xserver --viewport-size 1280x1024';//...
do
{
exec('export DISPLAY=":0";timeout '.$timoutTime.' wkhtmltopdf '.$shellArgs.' '.$htmlFilePath.' '.$pdfFilePath, $output, $exitStatus);
$currIteration++;
} while($exitStatus==$timeoutStatusCode && $currIteration<$maxIterations);
/*
* Make sure PDF creation was successful before post processing. Throw an exception if generation failed
*/
if($exitStatus==$timeoutStatusCode)
{
throw new Exception('PDF Generation failed for '.$htmlFilePath);
}