我猜passthru
被禁用于php.ini
出于安全原因用于 Web 服务器的文件。尝试执行以下代码:
function passthru_enabled() {
$disabled = explode(', ', ini_get('disable_functions'));
return !in_array('exec', $disabled);
}
if (passthru_enabled()) {
echo "passthru is enabled";
} else {
echo "passthru is disabled";
}
如果它被禁用,那么除非您可以编辑 php.ini 文件,否则您实际上无能为力。
编辑:另外,请确保在代码中启用错误报告,如果您尝试使用禁用的功能,代码还应该显示某种警告。将其放入您的代码中:
error_reporting(-1);
ini_set('display_errors', 'On');
Edit:
If passthru
启用,那么我能想到命令应该由命令行而不是 PHP 正确执行的唯一原因是因为它没有正确传递到命令行。尝试在参数周围添加引号转义shellarg http://www.php.net/manual/en/function.escapeshellarg.php.
$url = escapeshellarg('http://codante.org/linux-php-screenshot');
$command = "./wkhtmltoimage --width 164 --height 105 --quality 100 --zoom 0.2 $url file/test.jpg";
您可能还想利用第二个参数passthru
,它返回命令的退出状态。非零值表示存在错误。
passthru($command, $status);
if ($status != 0) {
echo "There was an error executing the command. Died with exit code: $status";
}
有关这些退出代码的列表可帮助您调试正在发生的情况,请参阅具有特殊含义的退出代码 http://tldp.org/LDP/abs/html/exitcodes.html