PHP exec命令出现奇怪错误?

PHP exec命令出现奇怪错误?,php,exec,json,Php,Exec,Json,我刚刚在PHP中使用了exec命令,我得到了这个奇怪的错误。 1我尝试使用如下php命令: test1.php内容: if (!function_exists('json_decode')) { $file = 'log.txt'; file_put_contents($file, "Fail to load JSON"); exit; }else{ $file = 'log2.txt'; file_put_contents($file, "Success to load JSON");

我刚刚在PHP中使用了exec命令,我得到了这个奇怪的错误。 1我尝试使用如下php命令: test1.php内容:

if (!function_exists('json_decode')) {

$file = 'log.txt';
file_put_contents($file, "Fail to load JSON");
exit;

}else{

$file = 'log2.txt';
file_put_contents($file, "Success to load JSON");
exit;

}
$test = exec( 'nohup nice php '.'test1.php');
在命令行中:>>php test1.php

我成功加载JSON解码。 但当我试着这样运行它时: Test2.php内容:

if (!function_exists('json_decode')) {

$file = 'log.txt';
file_put_contents($file, "Fail to load JSON");
exit;

}else{

$file = 'log2.txt';
file_put_contents($file, "Success to load JSON");
exit;

}
$test = exec( 'nohup nice php '.'test1.php');
我跑了
http://localhost/test2.php

然后我无法加载JSON解码


这意味着我似乎无法在exec命令中获得json_解码工作?发生了什么以及如何在exec命令中使用json_decode?

这是同一台主机吗?您是否可能在一台机器上运行
php test1.php
,而在另一台机器上运行带有
exec
的脚本?如果是,那么
json_decode
仅在PHP5.2.0之后可用。通过运行以下命令检查您的PHP版本:

php -i | grep 'PHP Version'

从另一个文件调用日志文件时,日志文件的路径是否可能不正确?另外,为什么不创建一个常规函数并调用它,而不是调用exec呢。