Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何给hprose的server做守护进程daemon? #27

Closed
forgottener opened this issue Sep 6, 2016 · 5 comments
Closed

如何给hprose的server做守护进程daemon? #27

forgottener opened this issue Sep 6, 2016 · 5 comments

Comments

@forgottener
Copy link

如题,像swoole的server是可以设置参数"daemonize" => true ,那么hprose呢?

@andot
Copy link
Member

andot commented Sep 6, 2016

一样的,你同样做这样的设置就可以了。

@forgottener
Copy link
Author

在hprose/hprose-php里全文搜索了'daemon',没有这个设置项吧?

@andot
Copy link
Member

andot commented Sep 6, 2016

是 swoole 的设置,使用 hprose-swoole 就可以了。

@forgottener
Copy link
Author

forgottener commented Sep 6, 2016

解决了,参考http://rango.swoole.com/archives/59 加个daemonize的方法

function daemonize()
{
        $pid = pcntl_fork();
        if ($pid == -1) {
            die("fork(1) failed!\n");
        } elseif ($pid > 0) {
            //让由用户启动的进程退出
            exit(0);
        }
        //建立一个有别于终端的新session以脱离终端
        posix_setsid();
        $pid = pcntl_fork();
        if ($pid == -1) {
            die("fork(2) failed!\n");
        } elseif ($pid > 0) {
            //父进程退出, 剩下子进程成为最终的独立进程
            exit(0);
        }
}
daemonize();
$server = new Server("tcp://0.0.0.0:1314");
$server->addFunction("hello");
$server->start();

@andot
Copy link
Member

andot commented Sep 6, 2016

原来你用的是 Hprose\Socket\Server 啊,这个 server 是为了方便在 windows 下调试用的,所以没用 pcntl 这个扩展。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants