Ejemplo n.º 1
0
$pool->submit(new WebWork());
/*
* The Workers in the Pool retain references to the WebWork objects submitted
* in order to release that memory the Pool::collect method must be invoked in the same
* context that created the Pool.
*
* The Worker::collect method is invoked for every Worker in the Pool, the garbage list
* for each Worker is traversed and each Collectable is passed to the provided Closure.
*
* The Closure must return true if the Collectable can be removed from the garbage list.
*
* Worker::collect returns the size of the garbage list, Pool::collect returns the sum of the size of
* the garbage list of all Workers in the Pool. 
*
* Collecting in a continuous loop will cause the garbage list to be emptied.
*/
while ($pool->collect(function ($work) {
    return $work->isGarbage();
})) {
    continue;
}
/*
* We could submit more stuff here, the Pool is still waiting for Collectables
*/
$logger->log(function ($pool) {
    var_dump($pool);
}, $pool);
/*
* Shutdown Pools at the appropriate time, don't leave it to chance !
*/
$pool->shutdown();
Ejemplo n.º 2
0
/*
* The Workers in the Pool retain references to the WebWork objects submitted
* in order to release that memory the Pool::collect method must be invoked in the same
* context that created the Pool.
*
* The Worker::collect method is invoked for every Worker in the Pool, the garbage list
* for each Worker is traversed and each Collectable is passed to the provided Closure.
*
* The Closure must return true if the Collectable can be removed from the garbage list.
*
* Worker::collect returns the size of the garbage list, Pool::collect returns the sum of the size of
* the garbage list of all Workers in the Pool.
*
* Collecting in a continuous loop will cause the garbage list to be emptied.
*/
while ($pool->collect(function ($work) {
    return !$work->isRunning();
})) {
    continue;
}
/*
* We could submit more stuff here, the Pool is still waiting for Collectables
*/
$logger->log(function ($pool) {
    echo '-----------------------';
    var_dump($pool);
}, $pool);
/*
* Shutdown Pools at the appropriate time, don't leave it to chance !
*/
$pool->shutdown();