Home  >  Article  >  Backend Development  >  【PHP】PHP进程系列-学习篇(1)

【PHP】PHP进程系列-学习篇(1)

WBOY
WBOYOriginal
2016-06-23 13:06:05993browse

    $nowPID=getmypid(); //获取当前主进程的PID

    $PID=pcntl_fork();//创建一个子进程  创建成功时。PID=0(子进程)  PID>0(父进程)

    if($PID ==-1){
        die('子进程创建失败');
    }
    else if($PID){
        echo "【父进程】我的PID是:".$nowPID.",子进程PID:".$PID."
";

    }else{
        $forkPID=getmypid(); //获取当前主进程的PID
        file_put_contents("子进程任务.txt", "【子进程】我的PID是:".$forkPID.",父进程PID:".$nowPID); //子进程会执行自己的任务
    }


    file_put_contents(getmypid().".txt", "进程"); //子进程会执行自己的任务
    exit('进程结束');

Statement:
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
Previous article:更新多条数据Next article:php时间戳