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.是啊.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...