简体   繁体   中英

PHP Gearman - idle when no workers available

Is it possible to idle the Client when all workers are working?

I have the following case:

$client= new GearmanClient();
$client->addServer();

$data = array(thousands of entries);

foreach($data as $dt) {
    $client->doBackground('doFancy', $dt);
}

When I run this, it will make thousands of queues or even overload the memory.

Is it possible to wait for a worker to become free until the foreach loop continues assigning new jobs?

You can create counter for queue size and set callback for complete event. In this callback you have to decrements counter and check the counter and if it's value less than N - new bunch of tasks will added and counter increments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM