Home > php教程 > php手册 > PHP daemon(使用pcntl_fork派生子进程后退出父进程)

PHP daemon(使用pcntl_fork派生子进程后退出父进程)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:37:57
Original
1635 people have browsed it

使用pcntl_fork派生子进程后退出父进程 无 ?phpfunction daemon(){ $pid = pcntl_fork(); if ($pid == -1) { exit(1); } elseif ($pid 0) { exit(0); } else { posix_setsid(); umask(0); chdir('/'); fclose(STDOUT); fclose(STDERR); $pid = pcntl_fork();

使用pcntl_fork派生子进程后退出父进程
<?php

function daemon()
{
    $pid = pcntl_fork();

    if ($pid == -1)
    {
        exit(1);
    }
    elseif ($pid > 0)
    {
        exit(0);
    }
    else
    {
        posix_setsid();
        umask(0);
        chdir(&#39;/&#39;);
        fclose(STDOUT);
        fclose(STDERR);

        $pid = pcntl_fork();

        if ($pid == -1)
        {
            exit(1);
        }
        elseif ($pid > 0)
        {
            exit(0);
        }
        else
        {
            unset($pid);
        }

    }
}

function job()
{
    // your job here
}

daemon();

while (true)
{
    job();
    sleep(1);
}
Copy after login
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template