Strange error with PHP exec command?
I just used exec command in PHP and I got this strange error. 1. I try to used php command like this : test1.php content :
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;
}
In command line : >>php test1.php
I got Success to load JSON decode. But when i tried to run it like this: Test2.php content :
$test = exec( 'nohup n开发者_开发知识库ice php '.'test1.php');
I ran http://localhost/test2.php
Then I got Fail to load JSON decode .
That mean seem I can't get json_decode work within exec command ? What's happen and how to use json_decode within exec command ?
Is this the same host? Is it possible, that you run php test1.php
on one machine, but script with exec
on another? If so, then json_decode
is only available since PHP 5.2.0. Check your PHP version by running this:
php -i | grep 'PHP Version'
精彩评论