swoole_process->start

ִ��forkϵͳ���ã�����̡�

int swoole_process->start();

�����ɹ������ӽ��̵�PID������ʧ�ܷ���false����ʹ��swoole_errno��swoole_strerror�õ�������ʹ�����Ϣ��

ִ�к��ӽ��̻ᱣ�ָ����̵��ڴ����Դ���縸�����ڴ�����һ��redis���ӣ���ô���ӽ��̻ᱣ��˶������в������Ƕ�ͬһ�����ӽ��еġ�

ע������

��Ϊ�ӽ��̻�̳и����̵��ڴ��IO������������������Ҫ��������ӽ��̣����Ҫ�ȴ�������Ϻ���ʹ�� swoole_event_add/�첽swoole_client/��ʱ��/�ź����첽IO������

����Ĵ���

$workers = [];
$worker_num = 3;//�����Ľ�����

for($i=0;$i<$worker_num ; $i++){
    $process = new swoole_process('process');
    $pid = $process->start();
    $workers[$pid] = $process;
    //�ӽ���Ҳ��������¼�
    swoole_event_add($process->pipe, function ($pipe) use($process){
    $data = $process->read();
        echo "RECV: " . $data.PHP_EOL;
    });
}


function process(swoole_process $process){// ��һ������
    $process->write($process->pid);
    echo $process->pid,"\t",$process->callback .PHP_EOL;
}

��ȷ�Ĵ��룺

$workers = [];
$worker_num = 3;//�����Ľ�����

for($i=0;$i<$worker_num ; $i++){
    $process = new swoole_process('process');
    $pid = $process->start();
    $workers[$pid] = $process;
}

foreach($workers as $process){
    //�ӽ���Ҳ��������¼�
    swoole_event_add($process->pipe, function ($pipe) use($process){
    $data = $process->read();
        echo "RECV: " . $data.PHP_EOL;
    });
}

function process(swoole_process $process){// ��һ������
    $process->write($process->pid);
    echo $process->pid,"\t",$process->callback .PHP_EOL;
}