當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Worker::run方法代碼示例

本文整理匯總了PHP中Worker::run方法的典型用法代碼示例。如果您正苦於以下問題:PHP Worker::run方法的具體用法?PHP Worker::run怎麽用?PHP Worker::run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Worker的用法示例。


在下文中一共展示了Worker::run方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: run

 public function run()
 {
     $count = 0;
     echo "Loading initial data...\n";
     $this->db = wfGetDB(DB_SLAVE, null, 'wikicities');
     $this->loadIndex();
     $this->loadImagePaths();
     echo "Processing...\n";
     foreach ($this->meta as $city) {
         echo " {$city['dbname']} ";
         flush();
         if ($this->dataExists($city['dbname'])) {
             echo "skipped (data already exists)\n";
             continue;
         }
         $lock = Lock::acquire_return('iter-' . $city['id']);
         if (!$lock) {
             echo "skipped (lock taken)\n";
             continue;
         }
         $worker = new Worker($city['dbname'], $city);
         if ($worker->run()) {
             $city = array_merge($city, $worker->get());
             $this->save($city['dbname'], $city);
         }
         $lock->release();
         echo "done\n";
     }
 }
開發者ID:Tjorriemorrie,項目名稱:app,代碼行數:29,代碼來源:collect.php

示例2: run

 public function run()
 {
     $this->onMessage = array($this, 'onMessage');
     parent::run();
 }
開發者ID:suhanyujie,項目名稱:hprose-workerman,代碼行數:5,代碼來源:HproseWorkermanService.php

示例3: init

$optsConfig = array('help|h' => 'Skrypt do generowania maili i smsów do wysyłki.', 'action|a=s' => "Lista dostępnych akcji: getsms|getmail|setupsms|setupmail");
include 'init.php';
class Worker extends Logic_Cmd_Action
{
    protected $_worker;
    public function init()
    {
        parent::init();
        $this->_worker = new GearmanWorker();
    }
    protected function runAction()
    {
        $this->_worker->addServer();
        $this->_worker->addFunction('setup', array(new Logic_Gearman_Worker_Setup(), "setup"));
        $this->_worker->addFunction('sendpackage', array(new Logic_Gearman_Worker_Send(), "sendpackage"));
        while (1) {
            try {
                $this->_worker->work();
                // work() will block execution until a job is delivered
            } catch (Exception $exc) {
                $this->_logger->err($exc->getMessage());
            }
            if ($this->_worker->returnCode() != GEARMAN_SUCCESS) {
                $this->_logger->err("An error has occured during gearman worker process..");
            }
        }
    }
}
$cmd = new Worker($opts, $application);
$cmd->run();
開發者ID:knatorski,項目名稱:SMS,代碼行數:30,代碼來源:worker.php

示例4: forkOneWorker

 /**
  * 創建一個子進程
  * @param Worker $worker
  * @throws Exception
  */
 protected static function forkOneWorker($worker)
 {
     $pid = pcntl_fork();
     // 獲得可用的id
     $id = self::getId($worker->workerId, 0);
     // 主進程記錄子進程pid
     if ($pid > 0) {
         self::$_pidMap[$worker->workerId][$pid] = $pid;
         self::$_idMap[$worker->workerId][$id] = $pid;
     } elseif (0 === $pid) {
         // 如果設置了端口複用,則在子進程執行監聽
         if ($worker->reusePort) {
             $worker->listen();
         }
         // 啟動過程中嘗試重定向標準輸出
         if (self::$_status === self::STATUS_STARTING) {
             self::resetStd();
         }
         self::$_pidMap = array();
         self::$_workers = array($worker->workerId => $worker);
         Timer::delAll();
         self::setProcessTitle('WorkerMan: worker process  ' . $worker->name . ' ' . $worker->getSocketName());
         self::setProcessUser($worker->user);
         $worker->id = $id;
         $worker->run();
         exit(250);
     } else {
         throw new Exception("forkOneWorker fail");
     }
 }
開發者ID:lisonglin0129,項目名稱:LDFRAMEWORK,代碼行數:35,代碼來源:Worker.php


注:本文中的Worker::run方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。