php – exec()和phantomjs问题与绝对路径
发布时间:2020-12-13 17:58:44 所属栏目:PHP教程 来源:网络整理
导读:我正在使用 phantomJS 来编程获取网页的屏幕截图.我的网络服务器在Linux 64位上运行. 情景 我的test.php文件 exec('./phantomjs --version',$o,$e);print_r($o);echo $e; 我在浏览器中打开test.php.我得到的输出是: 1.9.1 // version number0 // exit code
我正在使用
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的第二个参数会导致它崩溃.因此,我想知道的是: >我的假设是对的吗?
经过大量的搜索和测试后,我得到了以下新增功能:
//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.是啊. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |