我試圖通過CLISystem_Daemon未能打開流/var/log/mydaemonname.log
function doTask(){
echo 'mytest';
}
// Include PEAR's Daemon Class
require_once "/usr/share/php/System/Daemon.php";
// Bare minimum setup
System_Daemon::setOption("appName", "mydaemonname2");
try{
// Spawn Deamon!
System_Daemon::start();
// Your PHP Here!
while (true) {
doTask();
}
// Stop daemon!
System_Daemon::stop();
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
notice: Starting mydaemonname daemon, output in: '/var/log/mydaemonname.log'
[Feb 08 12:17:23] warning: [PHP Error] file_put_contents(/var/log/mydaemonname.log): failed to open stream: Permission denied
無論是在我的本地主機,在我的dev的服務器來運行這個簡單的守護進程。
如果我試圖粗略創建和設置CHMOD 777文件權限/var/log/mydaemonname.log 我得到這個其他錯誤
[Feb 08 12:30:31] notice: Starting mydaemonname daemon, output in: '/var/log/mydaemonname.log'
[Feb 08 12:30:31] err: Unable to create directory: '/var/run/mydaemonname' [l:1366]
[Feb 08 12:30:31] emerg: Unable to write pid file /var/run/mydaemonname/mydaemonname.pid [l:1272]
[Feb 08 12:30:31] info: Process was not daemonized yet, just halting current process
,如果我嘗試設置777文件權限到/ var /運行/ mydaemonname我得到這個在日誌文件中
notice: Starting mydaemonname daemon, output in: '/var/log/mydaemonname.log'
[Feb 08 12:17:06] err: Unable to change group of file '/var/run/mydaemonname/mydaemonname.pid' to 0 [l:1425]
[Feb 08 12:17:06] crit: Unable to change identity [l:1281]
[Feb 08 12:17:06] emerg: Cannot continue after this [l:1283]
你能幫助我嗎?
再見
您可能需要設置選項appRunAsUID,appRunAsGID,appPidLocation和logLocation。 – rik 2011-02-08 15:32:09
我試過$ path = dirname(__ FILE__); System_Daemon :: setOption(「appName」,「mydaemonnew」); System_Daemon :: setOption(「appRunAsUID」,0); System_Daemon :: setOption(「appRunAsGID」,0); System_Daemon :: setOption(「appPidLocation」,$ path。'/ mypid'); System_Daemon :: setOption(「logLocation」,$ path。'/ mylog'); – Whisher 2011-02-08 17:35:28