gpt4 book ai didi

php - System_Daemon 无法打开流/var/log/mydaemonname.log

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:39:56 24 4
gpt4 key购买 nike

我正在尝试通过 cli 运行这个简单的守护进程

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

在我的本地主机和我的开发服务器中。

如果我尝试粗略地创建 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

如果我尝试为/var/run/mydaemonname 设置 777 文件权限,我会在日志文件中得到它

 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]

你能帮帮我吗?

再见

最佳答案

您以什么用户身份启动守护程序?如果它不是 root 那么这可能是你的答案:

选项“appRunAsUID”和“appRunAsGID”设置用户认为守护进程应该切换到子(守护进程)进程中使用。它需要以用户“root”身份启动,以便能够正确访问 pid 文件。

因此,您应该将“appRunAsUID”和“appRunAsGID”设置为守护脚本将运行的非特权用户,但您需要以“root”身份启动进程才能写入 pid 和切换用户。

关于php - System_Daemon 无法打开流/var/log/mydaemonname.log,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4932501/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com