带phantomjs的Windows PHP exec / shell_exec始终返回null

问题描述 投票:1回答:3

我正在Windows服务器上运行PHP 5.4.9

我已经尝试在PHP中运行所有脚本命令(exec,shell_exec,system,proc_open,passthru)。所有人似乎都返回空或null。

我已将phantomjs添加为PATH变量。

并在命令提示符下运行phantomjs --version,并返回1.8.2

虽然我尝试跑步

$return = exec("phantomjs --version")

$return = shell_exec("phantomjs --version", $output)

[$return始终为空,$output为空。

我确保IUSR和IIS_IUSRS用户具有运行phantomjs.exe的权限

在php.ini中禁用了安全模式

而且,我尝试运行exec('ls') && exec('ipconfig /all'),并且那些输出了我期望的数据。

我不确定还有什么尝试。

php windows exec phantomjs
3个回答
1
投票

我面临着同样的问题。事实是phantomjs需要所有的完整路径这是我想出的解决方案:

$getout = exec('D:\\xampp\\htdocs\\phantomjsdir\\phantomjs.exe D:\\xampp\\htdocs\\rasterisejsdir\\rasterize.js http://localhost/pagetobecaptured/test D:\\xampp\\htdocs\\outputfiledir\\test2.jpg "1800px*840px"',$o,$e);

0
投票

您已经很接近解决方案了。基本上是:

$stdout = shell_exec('time /T');
echo $stdout;

您需要确保幻影二进制文件在路径上或以全路径调用。

有关执行PhantomJS的完整示例,请参见driver file of "jakoch/PHPUnit-headless"


0
投票

我使用php 7.2从proc_open不断获得NULL的返回值,这可能是导致该问题的原因,但是在Windows上,生成的进程pid是有效的(该进程长时间运行):

$descriptorspec = array(
    0 => array("pipe", "r"), // stdin for worker
    1 => array("pipe", "w"), // stdout for worker
    2 => array("pipe", "w"), // stderr for worker
);
$user->worker = proc_open('C:\wamp64\bin\php\php7.2.18\php watch.php', $descriptorspec, $user->pipes); 
if(is_resource($user->worker)) 
{
    $ppid = proc_get_status($user->worker)['pid'];
    echo "WORKER:".var_export($user->worker, true)." pid ".$ppid);
}

这存储在派生类“ user”的实例的公共成员“ worker”中

我应该尝试array('bypass_shell'=> true));也许作为proc_open的选项以避免cmd shell,感谢您提供任何线索

© www.soinside.com 2019 - 2024. All rights reserved.