(PECL pthreads >= 3.0.0)
Worker::collect — Recopila las referencias de las tareas finalizadas
Permite al worker recopilar las referencias determinadas como migajas por el collector eventualmente proporcionado.
collector
Una función de retrollamada que devuelve un booleano sobre la posibilidad de recopilar la tarea o no. Solo en casos raros debería utilizarse un collector personalizado.
El número de tareas restantes en la pila del worker a recopilar.
Ejemplo #1 Un ejemplo básico de Worker::collect()
<?php
$worker = new Worker();
echo "There are currently {$worker->collect()} tasks on the stack to be collected\n";
for ($i = 0; $i < 15; ++$i) {
$worker->stack(new class extends Threaded {});
}
echo "There are {$worker->collect()} tasks remaining on the stack to be collected\n";
$worker->start();
while ($worker->collect()); // bloque hasta que todas las tareas estén finalizadas
echo "There are now {$worker->collect()} tasks on the stack to be collected\n";
$worker->shutdown();
El resultado del ejemplo sería:
There are currently 0 tasks on the stack to be collected There are 15 tasks remaining on the stack to be collected There are now 0 tasks on the stack to be collected