php - 使用 shell_exec 執行 shell 指令

php - 使用 shell_exec 執行 shell 指令

我正在使用 ajax 呼叫在伺服器(centos)上執行“shell_exec”。我正在執行的行如下

echo shell_exec("php -q /websockets/timedactions.php");

這是伺服器回應:

X-Powered-By: PHP/5.5.16
Access-Control-Allow-Origin: http://myIpAddress
Access-Control-Allow-Credentials: true
Content-type: text/html

運行此命令後,它應該激活的進程似乎沒有運行。

使用 root 存取權限在 shell 上呼叫相同的命令

php -q /websockets/timedactions.php

工作完美。

如何使用 shell_exec 使腳本運作?

更多資訊:

ps aux | grep httpd | awk '{print $1}' = nobody


sestatus|grep enforcing = {no result}


file permissions -rwxr-xr-x 1 root root 


ls -lZ timedactions.php -rwxr-xr-x root root ? timedactions.php*

答案1

好吧,那麼

似乎答案非常簡單(儘管可能令人沮喪:-))我剛剛添加了 PHP 的完整路徑。真的不知道為什麼我之前沒有收到任何錯誤以及為什麼它有效(如果有人可以解釋的話)

shell_exec('/usr/local/bin/php -q /websockets/timedactions.php /dev/null 2>&1 &');

謝謝你的嘗試...

相關內容