php – exec()和phantomjs问题与绝对路径

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – exec()和phantomjs问题与绝对路径脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 phantomJS来编程获取网页的屏幕截图.我的网络服务器在Linux 64位上运行.

情景

我的test.PHP文件

exec('./phantomjs --version',$o,$e);
PRint_r($o);
echo $e;

我在浏览器中打开test.PHP.我得到的输出是:

1.9.1 // version number
0 // exIT code

这证明我可以通过exec()运行命令,并且phantomJS工作正常.

问题

现在我用以下代码替换上面的代码

exec('./phantomjs http://mywebsite.COM/test.js',$e);
print_r($o);
echo $e;

输出是:

Array ( ) // empty output
139 // exit code which on investigating turned out to be segmentation fault

我也尝试过:

exec('./phantomjs ./test.js',$e); // since phantomjs and test.js are in same folder

但结果是一样的(段错误)

test.js代码

VAR page = require('webpage').create();
var url = 'http://www.rediff.com/';
page.oPEn(url,function (status) {
    phantom.exit();
});

这让我相信使用完整路径作为phantomJS的第二个参数会导致它崩溃.因此,我想知道的是:

>我的假设是对的吗?
>或者是因为我的网络服务器的一些限制阻止了exec()通过绝对URL访问.js文件

经过大量的搜索和测试后,我得到了以下新增功能
//throws a lot of errors because seArching some libraries
$cmd = 'unset DYLD_LIBRARY_PATH ;';
$cmd.= ' /abs/path/to/phantomjs';
$cmd.= ' /abs/path/to/script.js';

//set environment variable to node source
putenv('PATH=/abs/path/to/node/bin/');

//Now exec the cmd and pipe the errors to stdout
exec($cmd.' 2>&1',$output);

//and output the results
print_r($output);

我不是最好的服务器管理员,所以我无法详细解释所有内容,但上面的行生成一个pDF.是啊.

脚本宝典总结

以上是脚本宝典为你收集整理的php – exec()和phantomjs问题与绝对路径全部内容,希望文章能够帮你解决php – exec()和phantomjs问题与绝对路径所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。