使用exec()从PHP运行PhantomJS [英] Running PhantomJS from PHP with exec()

查看:210
本文介绍了使用exec()从PHP运行PhantomJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下脚本:

#!/bin/sh
export DISPLAY=:0
phantomjs --version

它尝试通过以下PHP脚本运行它:

It try to run it from the following PHP script:

<?php
$result = shell_exec('sh test.sh'); 
echo $result;
?>

此脚本返回以下错误:

[Thu Jun 19 10:31:31 2014] [error] [client] test.sh: line 3: phantomjs: command not found

我尝试在控制台中手动运行phantomjs -v,并且运行正常.我检查了PATH,并正确定义并找到了phantomjs.

I tried to run phantomjs -v by hand in a console, and it runs fine. I checked the PATH, and phantomjs is correctly defined and found.

执行环境是具有LiveConfig的虚拟服务器. 有人可以帮助我了解我在做什么错吗?

The execution environment is a virtual Server with LiveConfig. Can someone help me understand what I'm doing wrong ?

推荐答案

您的PATH可能缺少phantomjs可执行文件的位置. PhantomJS可能已安装在/usr/local/bin中,因此您需要将其添加到PATH变量中:

Your PATH probably lacks the location for the phantomjs executable. PhantomJS is probably installed in /usr/local/bin so you need to add this to your PATH variable:

#!/bin/sh
export DISPLAY=:0
PATH=$PATH:/usr/local/bin
phantomjs --version

要检查当前的PATH是什么,可以使用以下命令开始shell脚本:

To check what the current PATH is, you could begin the shell script with:

#!/bin/sh
echo $PATH

这篇关于使用exec()从PHP运行PhantomJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆