wkhtmltopdf を使用して Web サイトのページを変換しようとしましたが、同じページの変換に失敗しています。外部ページを変換して保存するので(googleとbbc.co.ukで試してみましたが、どちらもうまくいきました)、アクセス許可は問題ありませんが、静的htmlファイルまたはスクリプトによって生成されたローカルページを変換しようとすると、失敗するまでに約 3 分かかります。
出力には、ページの読み込みに失敗したと表示されます。これを強制的に無視すると、空白の PDF が表示されます。
セッションのロックかもしれないと思いましたが、セッションを閉じると同じ問題が発生しました。私はそれがサーバーの動作にあるかもしれない方法に何かあると感じています
問題のコードは次のとおりです。
session_write_close ();
set_time_limit (0);
ini_set('memory_limit', '1024M');
Yii::app()->setTheme("frontend");
// Grabbing the page name
$ls_url = Yii::app()->request->getHostInfo().Yii::app()->request->url;
// Let's remove the PDF otherwise we'll be in endless loop
$ls_url = str_replace('.pdf','',$ls_url);
// Setting paths
$ls_basePath = Yii::app()->basePath."/../extras/wkhtmltopdf/";
if(PHP_OS=="Darwin")
$ls_binary = $ls_basePath . "wkhtmltopdf-osx";
else
$ls_binary = $ls_basePath . "wkhtmltopdf";
$ls_generatedPagesPath = $ls_basePath . "generated-pages/";
$ls_outputFileName = str_replace(array("/",":"),"-",$ls_url)."--".date("dmY-His").".pdf";
$ls_outputFile = $ls_generatedPagesPath. $ls_outputFileName;
// making sure no nasty chars are in place
$ls_command = escapeshellcmd($ls_binary ." --load-error-handling ignore " . $ls_url . " " . $ls_outputFile);
// Let's run things now
system($ls_command);