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

进程残留 #1

Open
xpader opened this issue Jul 25, 2019 · 0 comments
Open

进程残留 #1

xpader opened this issue Jul 25, 2019 · 0 comments

Comments

@xpader
Copy link

xpader commented Jul 25, 2019

<?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 掉)。但实际上任务已经完全运行完了。

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

1 participant