>我在shell上执行这个,我得到结果
[root@s1 ~]# phantomjs/opt/phantomjs/examples/hello.js世界您好!
但是如何通过浏览器在 php 上执行此操作?
在 php 中使用exec
函数发出与在 shell 中相同的调用。
exec("/opt/phantomjs/bin/phantomjs /opt/phantomjs/examples/hello.js", $output);
echo $output;
最好使用二进制文件和脚本的完整路径,以避免查找 fike 时出现问题,因为您的 php 脚本可能位于完全不同的位置。