简体   繁体   English

从PHP调用时PhantomJS无法渲染

[英]PhantomJS Fails to Render When Called from PHP

I have a one-liner that generates a PDF from an HTML file: 我有一个单行代码,可从HTML文件生成PDF:

$my_path = "/path/to/phantomjs/and/generate-pdf.js";
$output  = shell_exec("cd $my_path && phantomjs generate-pdf.js");

I can run this command successfully from the shell as the root user, myself, and the apache user (www-data). 我可以以root用户,本人和apache用户(www-data)的身份从Shell成功运行此命令。 Even more, I can run this same line of code successfully from a PHP file called from the command-line as php generate-pdf.php , and I'm able to run other shell commands such as touch test.txt just fine from an HTTP request. 更重要的是,我可以从命令行调用的PHP文件成功运行同一行代码,如php generate-pdf.php ,而且我可以运行其他shell命令(如touch test.txt就可以了。 HTTP请求。

Why am I unable to generate the PDF when called from an HTTP request? 为什么从HTTP请求调用时无法生成PDF?

The entire directory structure (including the phantomjs executable and generate-pdf.js) has been given 777 permissions, safe_mode has been disabled from both /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini , and disable_functions does not include shell_exec . 整个目录结构(包括phantomjs可执行文件和generate-pdf.js)已被授予777权限,从/etc/php5/apache2/php.ini/etc/php5/cli/php.ini都禁用了safe_mode ,和disable_functions不包括shell_exec

If you made sure that shell_exec() itself is enabled, I guess it is a $PATH issue. 如果您确保启用了shell_exec()本身,我想这是一个$PATH问题。 You should execute it given the full path to the phantomjs binary: 给定phantomjs二进制文件的完整路径,您应该执行它:

shell_exec("cd $my_path && /path/to/phantomjs generate-pdf.js");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM