Skip to content

进程残留 #1

@xpader

Description

@xpader
<?php

require './SimpleFork.php';

$sf = new SimpleFork(2, 'my-process'); // 2代表子进程数, 'my-process'是进程的名字

$sf->master(function ($sf) {
    // 主进程的方法请包裹在master里
    for ($i=0; $i<100; $i++) {
        $sf->submit('http://www.google.cn/', function ($data) { // 使用submit方法将其提交到一个空闲的进程,如果没有空闲的,系统会自动等待
            echo $data;
        });
    }
    $sf->wait();
})->slave(function ($url, $sf) {
    $sf->log('fetch %s', $url); // 使用内置的log方法,子进程的log也会被打印到主进程里
	return $url;
});

使用以上代码在 MacOS 上运行完成后,总会有两三个 php 进程仍然存活(只能强制 kill 掉)。但实际上任务已经完全运行完了。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions