1
我剛剛在PHP中使用exec命令,我得到了這個奇怪的錯誤。 1.我嘗試使用PHP的命令是這樣的: test1.php內容: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;
}
在命令行:>> PHP test1.php
我成功加載JSON解碼。 但是,當我試圖像這樣運行: Test2.php內容:
$test = exec('nohup nice php '.'test1.php');
我跑http://localhost/test2.php
然後我無法加載JSON解碼。
這意味着我不能讓json_decode在exec命令中工作嗎?發生什麼事以及如何在exec命令中使用json_decode?
當你從另一個文件調用它時,你的日誌文件的路徑是不正確的嗎?另外,爲什麼不只是創建一個普通的函數,並調用它而不是調用exec。 – TJHeuvel