本文整理汇总了PHP中SimpleSocket::send方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleSocket::send方法的具体用法?PHP SimpleSocket::send怎么用?PHP SimpleSocket::send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleSocket
的用法示例。
在下文中一共展示了SimpleSocket::send方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: runWorkerProcess
/**
* Run the worker process
* @param \QXS\WorkerPool\WorkerInterface $worker the worker, that runs the tasks
* @param \QXS\WorkerPool\SimpleSocket $simpleSocket the simpleSocket, that is used for the communication
* @param int $i the number of the child
*/
protected function runWorkerProcess(WorkerInterface $worker, SimpleSocket $simpleSocket, $i)
{
$replacements = array('basename' => basename($_SERVER['PHP_SELF']), 'fullname' => $_SERVER['PHP_SELF'], 'class' => get_class($worker), 'i' => $i, 'state' => 'free');
ProcessDetails::setProcessTitle($this->childProcessTitleFormat, $replacements);
$this->worker->onProcessCreate($this->semaphore);
while (TRUE) {
$output = array('pid' => getmypid());
try {
$replacements['state'] = 'free';
ProcessDetails::setProcessTitle($this->childProcessTitleFormat, $replacements);
$cmd = $simpleSocket->receive();
// invalid response from parent?
if (!isset($cmd['cmd'])) {
break;
}
$replacements['state'] = 'busy';
ProcessDetails::setProcessTitle($this->childProcessTitleFormat, $replacements);
if ($cmd['cmd'] == 'run') {
try {
$output['data'] = $this->worker->run($cmd['data']);
} catch (\Exception $e) {
$output['workerException'] = array('class' => get_class($e), 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString());
}
// send back the output
$simpleSocket->send($output);
} elseif ($cmd['cmd'] == 'exit') {
break;
}
} catch (SimpleSocketException $e) {
break;
} catch (\Exception $e) {
// send Back the exception
$output['poolException'] = array('class' => get_class($e), 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString());
$simpleSocket->send($output);
}
}
$this->worker->onProcessDestroy();
$this->exitPhp(0);
}