private function _launchWorkers($address = null, $workers = null)
{
//Minimum number of the workers that should be
$workers = $workers ?: $this->config()->workers;
$service = $address ?: $this->name;
//Number of the workers which are working now
$availableWorkers = $this->isServiceRegistered($service);
if ($availableWorkers === false) {
throw new TaskException(sprintf("Broker did not respond. Terminating client %s", $service));
}
$this->log("DEBUG", "%d avalilable workers for %s service", $availableWorkers, $service);
//Service might be registered but workers has already gone
if ($availableWorkers < $workers) {
//Workers have not been launched yet. Starting them
for ($i = $availableWorkers; $i < $workers; ++$i) {
//It is important to save a PID of the process
$pid = $this->addWorker($service);
$this->pids[$pid] = $pid;
}
}
return max($workers, $availableWorkers);
}