当前位置: 首页>>代码示例>>PHP>>正文


PHP SimpleSocket::receive方法代码示例

本文整理汇总了PHP中SimpleSocket::receive方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleSocket::receive方法的具体用法?PHP SimpleSocket::receive怎么用?PHP SimpleSocket::receive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleSocket的用法示例。


在下文中一共展示了SimpleSocket::receive方法的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);
 }
开发者ID:sajib-hassan,项目名称:WorkerPool,代码行数:45,代码来源:WorkerPool.php


注:本文中的SimpleSocket::receive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。