我正在嘗試使用反引號操作符來運行shell命令,但子進程繼承php的打開文件描述符的事實是有問題的。有沒有辦法阻止這種情況的發生?沒有孩子的PHP fork會繼承父級的文件描述符?
我運行PHP 5.1.2
我正在嘗試使用反引號操作符來運行shell命令,但子進程繼承php的打開文件描述符的事實是有問題的。有沒有辦法阻止這種情況的發生?沒有孩子的PHP fork會繼承父級的文件描述符?
我運行PHP 5.1.2
我真的知道的唯一方法是讓孩子分叉後,開闢出屬於自己的資源。
有上了pcntl一個相當不錯的教程在這裏:
http://hudzilla.org/phpwiki/index.php?title=Miscellaneous_topics
http://hudzilla.org/phpwiki/index.php?title=Duplication_of_resources_when_forking
這爲我工作:
$cmd_to_run = escapeshellarg('/path/to/file --args');
`echo $cmd_to_run | /bin/at now`;
替換「/路徑/到/文件 - -args'部分與你想運行的命令。 'at'命令使用你的cron守護進程來安排任務。
更新後的鏈接:http://www.hackingwithphp.com/16/0/0/miscellaneous-topics和http://www.hackingwithphp.com/16/1/4/duplication-of-resources-when-分叉 – Greg 2015-09-16 16:11:17