简体   繁体   English

使用exec()从PHP运行PhantomJS

[英]Running PhantomJS from PHP using exec()

I'm trying to execute PhantomJS via PHP on my local host (MAMP) on MacOS. 我正在尝试在MacOS上的本地主机(MAMP)上通过PHP执行PhantomJS。

I've installed PhantomJS 我已经安装了PhantomJS

$ sudo cp phantomjs-1.9.8-macosx/bin/phantomjs /usr/local/bin

and made the file executable 并使文件可执行

$ sudo chmod +x /usr/local/bin/phantomjs

When I go to the folder containing my file hello.js and on the command line type 当我转到包含我的文件hello.js的文件夹并在命令行上键入时

$ phantomjs hello.js 

it works fine. 它工作正常。

However, when I try it in PHP on index.php, 但是,当我在index.php上的PHP中尝试时,

<?php
    $response = exec('/usr/local/bin/phantomjs hello.js');
    echo $response;
?>

I get nothing! 我什么都没有! What am I doing wrong? 我究竟做错了什么? Any help is greatly appreciated. 任何帮助是极大的赞赏。

<?php    
exec('/usr/local/bin/phantomjs path/hello.js');
?>

Yes. 是。 Sometimes phantomjs don't need full path in some environment without generate any error. 有时,phantomjs在某些环境中不需要完整路径而不会产生任何错误。 However, sometimes it does. 但是,有时确实如此。

Always use the full path for all argument in the php command. 始终对php命令中的所有参数使用完整路径。

Did you use the fullpath for hello.js? 您是否为hello.js使用了全路径?

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

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