【问题标题】:phantomjs not working using execphantomjs 无法使用 exec
【发布时间】:2015-11-08 09:35:12
【问题描述】:

我可以运行 phantomjs-netsniff 代码以在终端中创建 har 文件(以 root 身份),但是当我使用 php 执行它时,它返回确实创建了 har 文件但零位。两次执行相同的代码。

我在 php 中禁用了安全模式,对 har 生成文件夹有 777 权限。我错过了什么。

我的操作系统是 centos 64 位。我使用https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2 安装。

php代码

<?php

$rrd= 'phantomjs /var/www/xxx/netsniff.js "http://www.wiki.com" > /var/www/xxx/xx/xx.har';
exec($rrd);

?>

【问题讨论】:

  • 你能展示你的PHP代码吗?
  • 尝试检查错误。 $output = array(); $returnCode = null; exec($rrd, $output, $returnCode); print_r($output); echo "Return code was $returnCode\n"; 看看会发生什么。
  • 你完全救了我兄弟。它给了我错误 127,我更正了它。但这很奇怪。此代码已在另一台服务器上运行。为什么它会在此服务器上抛出错误(两者相同)? .你能把它作为答案而不是评论吗?

标签: php server phantomjs har


【解决方案1】:

您应该经常检查错误;这可以告诉你出了什么问题:

$output = array();
$returnCode = null;
exec($rrd, $output, $returnCode);
print_r($output);
echo "Return code was $returnCode\n";

从您的评论中,您说您得到了返回码 127,这通常意味着“找不到命令”。 phantomjs 在你的路上吗?如果您以运行 PHP 的用户身份键入 which phantomjs,您会得到什么?避免这种情况的一种简单方法是仅在命令中指定二进制文件的完整路径,即在命令字符串中使用 /path/to/phantomjs 而不是仅使用 phantomjs

【讨论】:

  • 代码前需要包含任何phantomjs文件
猜你喜欢
  • 1970-01-01
  • 2023-04-04
  • 2016-02-07
  • 1970-01-01
  • 2017-11-11
  • 2016-09-11
  • 1970-01-01
  • 2013-12-20
相关资源
最近更新 更多