小编inJ*_*uzi的帖子

为什么不是所有线程都完成?

我已经尝试过这个 Joe 回答/sf/answers/2253097241/ 中的示例,它运行良好,但是当我尝试稍微编辑此代码时:

$pool = new Pool(4);

while (@$i++<10) {
    $pool->submit(new class($i) extends Collectable {
        public function __construct($id) {
            $this->id = $id;
        }

        public function run() {
            printf(
                "Hello World from %d\n", $this->id);
        $this->html = file_get_contents('http://google.fr?q=' . $this->query);
            $this->setGarbage();
        }

        public $id;
public $html;
    });
}

while ($pool->collect(function(Collectable $work){
    printf(
        "Collecting %d\n", $work->id);
var_dump($work->html);
    return $work->isGarbage();
})) continue;

$pool->shutdown();
Run Code Online (Sandbox Code Playgroud)

“Hello world”的计数与“Collecting”的计数不同。文档已过时。这个问题怎么办?

php pthreads

5
推荐指数
1
解决办法
821
查看次数

标签 统计

php ×1

pthreads ×1