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


PHP swoole_process::start方法代碼示例

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


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

示例1: forkChildInWorker

function forkChildInWorker()
{
    global $serv;
    echo "on worker start\n";
    $process = new swoole_process(function (swoole_process $worker) {
        // 		$serv = new swoole_server( "0.0.0.0", 9503 );
        // 		$serv->set(array(
        // 				'worker_num' => 1
        // 		));
        // 		$serv->on ( 'receive', function (swoole_server $serv, $fd, $from_id, $data) {
        // 			$serv->send ( $fd, "Swoole: " . $data );
        // 			$serv->close ( $fd );
        // 		});
        // 		$serv->start ();
        // 		swoole_event_add ($worker->pipe, function ($pipe) use ($worker) {
        // 			echo $worker->read()."\n";
        // 		});
        // 		swoole_timer_add (1000, function ($interval) use ($worker) {
        // 			echo "#{$worker->pid} child process timer $interval\n"; // 如果worker中沒有定時器,則會輸出 process timer xxx
        // 		});
    });
    $pid = $process->start();
    echo "Fork child process success. pid={$pid}\n";
    //保存子進程對象,這裏如果不保存,那對象會被銷毀,管道也會被關閉
    $serv->childprocess = $process;
}
開發者ID:WenkeZhou,項目名稱:swoole-src,代碼行數:26,代碼來源:server.php

示例2: run

 function run($options)
 {
     $asDaemon = isset($options['asDaemon']) ? $options['asDaemon'] : 0;
     if ($asDaemon) {
         \swoole_process::daemon();
     }
     $pids = [];
     $workers = [];
     for ($i = 0; $i < $this->worker_num; $i++) {
         $process = new \swoole_process($this->workerStart, $this->redirect_stdout);
         $process->id = $i;
         $pid = $process->start();
         $pids[] = $pid;
         $workers[$pid] = $process;
     }
     $pidFile = isset($options['pidFile']) ? $options['pidFile'] : 0;
     if ($pidFile) {
         $ppid = posix_getpid();
         $pids[] = $ppid;
         file_put_contents($pidFile, implode("|", $pids));
     }
     \swoole_process::signal(SIGTERM, function () use($workers) {
         exit(0);
     });
     \swoole_process::signal(SIGINT, function () {
         exit(0);
     });
     \swoole_process::wait(false);
     return $workers;
 }
開發者ID:kerisy,項目名稱:framework,代碼行數:30,代碼來源:Process.php

示例3: run

 function run()
 {
     //swoole_process::daemon(0, 1);
     $this->start_time = $this->middle_time = microtime(true);
     if ($this->status == 'import') {
         $db = new mysqli('127.0.0.1', 'root', '', 'friend');
         //$db = new mysqli('119.254.111.25', 'myroot', 'jXIN@274.com', 'friend', 60002);
         $sql = "SELECT COUNT(*) FROM friend";
         if ($result = $db->query($sql)) {
             $row = $result->fetch_row();
             $this->data_row = $row[0];
             $result->free();
         }
         $db->close();
         echo 'total data count: ' . $this->data_row . PHP_EOL;
     }
     //$this->data_row = 100000;
     for ($i = 0; $i < $this->worker_num; $i++) {
         $process = new swoole_process(array($this, 'child_async'), $this->redirect_stdout);
         $process->id = $i;
         $pid = $process->start();
         $this->workers[$pid] = $process;
         //echo "Master: new worker, PID=".$pid."\n";
     }
     $this->master_async();
 }
開發者ID:shenxinyu,項目名稱:redis_rank,代碼行數:26,代碼來源:paralle_rank.php

示例4: onMessage

 public function onMessage(swoole_websocket_server $server, $frame)
 {
     var_dump($frame->data);
     $data = json_decode($frame->data, true);
     var_dump($data);
     $cmd = $data['cmd'];
     $is_block = isset($data['is_block']) ? $data['is_block'] : 0;
     if ($is_block) {
         if (isset($this->async_process[$frame->fd])) {
             $process = $this->async_process[$frame->fd];
         } else {
             $process = new swoole_process(array($this, 'onTmpProcess'), true, 2);
             $process->start();
             $this->async_process[$frame->fd] = $process;
             swoole_event_add($process->pipe, function () use($process, $frame) {
                 $data = $process->read();
                 var_dump($data);
                 $this->server->push($frame->fd, $data);
             });
         }
         $process->write($cmd);
         sleep(1);
     } else {
         $this->process->write($cmd);
         $data = $this->process->read();
         $this->server->push($frame->fd, $data);
     }
 }
開發者ID:jinchunguang,項目名稱:swoole-doc,代碼行數:28,代碼來源:shell_server.php

示例5: run

 static function run()
 {
     $table = new swoole_table(1024 * 256);
     $table->column('index', swoole_table::TYPE_INT);
     $table->column('serid', swoole_table::TYPE_INT);
     $table->column('data', swoole_table::TYPE_STRING, 64);
     $table->create();
     self::$table = $table;
     for ($i = 0; $i < self::$key_num; $i++) {
         $key = 'user_' . (self::$key_base + $i);
         $ret = self::$table->set($key, array('index' => $i, 'serid' => rand(1000, 9999), 'data' => "hello_world_{$i}"));
         if (!$ret) {
             echo "count {$i} failed.";
             break;
         }
     }
     for ($i = 0; $i < self::$worker_num; $i++) {
         $process = new swoole_process('UnitTest_Table::worker');
         $process->start();
         $workers[$i] = $process;
     }
     for ($i = 0; $i < self::$worker_num; $i++) {
         $exit = swoole_process::wait();
         echo "worker[{$i}] exit\n";
     }
 }
開發者ID:cjq,項目名稱:tests,代碼行數:26,代碼來源:table.php

示例6: create_process

 /**
  * 創建一個子進程
  * @param $task
  */
 public function create_process($id, $task)
 {
     $this->task = $task;
     $process = new swoole_process(array($this, "run"));
     if (!($pid = $process->start())) {
     }
     //記錄當前任務
     Crontab::$task_list[$pid] = array("start" => microtime(true), "id" => $id, "task" => $task);
 }
開發者ID:royalwang,項目名稱:swoole-crontab,代碼行數:13,代碼來源:Process.class.php

示例7: create_process

 /**
  * 創建一個子進程
  * @param $classname
  * @param $number
  * @param $redis
  */
 public function create_process($classname, $number, $redis)
 {
     $this->workers["classname"] = $classname;
     $this->workers["number"] = $number;
     $this->workers["redis"] = $redis;
     $process = new swoole_process(array($this, "run"));
     if (!($pid = $process->start())) {
     }
     //記錄當前任務
     Crontab::$task_list[$pid] = array("start" => microtime(true), "classname" => $classname, "number" => $number, "redis" => $redis, "type" => "worker", "process" => $process);
 }
開發者ID:noikiy,項目名稱:swoole-crontab,代碼行數:17,代碼來源:Worker.class.php

示例8: callback_timer_function

function callback_timer_function()
{
    $Handle = new TimingCall_Tasks();
    $Handle->upDaemonTime();
    $tasks = $Handle->readExecuteTasks();
    foreach ($tasks as $task) {
        $process = new swoole_process('callback_process_function', true);
        $process->write(json_encode($task));
        $process->start();
        $process->wait(false);
    }
}
開發者ID:imdaqian,項目名稱:Hi-Timed,代碼行數:12,代碼來源:cmd.php

示例9: worker_run

 private function worker_run()
 {
     for ($i = 0; $i < $this->process_number; $i++) {
         $process = new swoole_process(array($this, "worker_callback"), false, true);
         $pid = $process->start();
         self::$workers[$i] = $process;
         self::$workers_pipe[$process->pipe] = $process;
         self::$restart_event[$i] = event_new();
         //var_dump($process->pipe);
         event_set(self::$restart_event[$i], $process->pipe, EV_READ | EV_PERSIST, array($this, "relisten"));
         event_base_set(self::$restart_event[$i], $this->event_base);
         event_add(self::$restart_event[$i]);
     }
 }
開發者ID:zhangjingpu,項目名稱:yaf-lib,代碼行數:14,代碼來源:Processpool.php

示例10: run

 public function run()
 {
     $this->current_num = $this->min_worker_num;
     for ($i = 0; $i < $this->current_num; $i++) {
         $process = new swoole_process(array($this, 'task_run'), false, 2);
         $pid = $process->start();
         $this->process_list[$pid] = $process;
         $this->process_use[$pid] = 0;
     }
     foreach ($this->process_list as $process) {
         swoole_event_add($process->pipe, function ($pipe) use($process) {
             $data = $process->read();
             var_dump($data);
             $this->process_use[$data] = 0;
         });
     }
     swoole_timer_tick(1000, function ($timer_id) {
         static $index = 0;
         $index = $index + 1;
         $flag = true;
         foreach ($this->process_use as $pid => $used) {
             if ($used == 0) {
                 $flag = false;
                 $this->process_use[$pid] = 1;
                 $this->process_list[$pid]->write($index . "Hello");
                 break;
             }
         }
         if ($flag && $this->current_num < $this->max_worker_num) {
             $process = new swoole_process(array($this, 'task_run'), false, 2);
             $pid = $process->start();
             $this->process_list[$pid] = $process;
             $this->process_use[$pid] = 1;
             $this->process_list[$pid]->write($index . "Hello");
             $this->current_num++;
         }
         var_dump($index);
         if ($index == 10) {
             foreach ($this->process_list as $process) {
                 $process->write("exit");
             }
             swoole_timer_clear($timer_id);
             $this->process->exit();
         }
     });
 }
開發者ID:jinchunguang,項目名稱:swoole-doc,代碼行數:46,代碼來源:dynamic.php

示例11: memoryCheck

 protected function memoryCheck()
 {
     $process = new \swoole_process(function (\swoole_process $worker) {
         $worker->name("kerisy-rpcserver:memoryCheck");
         swoole_timer_tick(1000, function () {
             $serverName = "kerisy-rpcserver:master";
             Reload::load($serverName, 0.8);
             //                echo date('H:i:s')."\r\n";
             if (date('H:i') == '04:00') {
                 Reload::reload($serverName);
                 //休息70s
                 sleep(70);
             }
         });
     });
     $process->start();
 }
開發者ID:kerisy,項目名稱:framework,代碼行數:17,代碼來源:Base.php

示例12: createWorkerProcess

 public static function createWorkerProcess($className, $number, $options)
 {
     $reflector = new \ReflectionClass($className);
     if (!$reflector->implementsInterface("PHPKit\\Console\\Workers\\IWorker")) {
         defined('PHPKIT_RUN_DEBUG') && syslog(LOG_ERR, 'class [' . $className . '] is error');
         self::stop();
     } else {
         $process = new \swoole_process(function ($worker) use($className, $number, $options) {
             $worker->name(self::$child_process_name . str_replace('\\', '_', $className) . '_' . $number);
             $handler = new $className($options);
             $handler->tick($worker);
         });
         $pid = $process->start();
         self::$worker_list[$pid] = ['className' => $className, 'number' => $number, 'process' => $process, 'options' => $options];
         defined('PHPKIT_RUN_DEBUG') && syslog(LOG_INFO, 'create child process success:' . $pid);
     }
 }
開發者ID:mawenpei,項目名稱:swoole-crontab,代碼行數:17,代碼來源:Handler.php

示例13: start

 /**
  * @brief 啟動子進程
  */
 public function start()
 {
     $workerNum = $this->_objAha->getConfig()->get('aha', 'worker_num');
     for ($i = 0; $i < $workerNum; $i++) {
         $worker = new \Daemon\Asyncworker($this->_objAha);
         $process = new \swoole_process(array($worker, 'start'));
         //$process->daemon();
         $workerPid = $process->start();
         $this->_workers[$workerPid] = $process;
         $process->write("worker started!");
     }
     foreach ($this->_workers as $process) {
         $workerPid = \swoole_process::wait();
         echo "[Worker Shutdown][WorkerId] {$workerPid} " . PHP_EOL;
         unset($this->_workers[$workerPid]);
     }
 }
開發者ID:vucms,項目名稱:aha,代碼行數:20,代碼來源:Async.php

示例14: create_process

 /**
  * 創建一個子進程
  * @param $task
  */
 public function create_process($id, $task)
 {
     $this->task = $task;
     $process = new swoole_process(array($this, "run"));
     if (!($pid = $process->start())) {
     }
     //記錄當前任務
     Crontab::$task_list[$pid] = array("start" => microtime(true), "id" => $id, "task" => $task, "type" => "crontab", "process" => $process);
     swoole_event_add($process->pipe, function ($pipe) use($process) {
         $task = $process->read();
         list($pid, $sec) = explode(",", $task);
         if (isset(Crontab::$task_list[$pid])) {
             $tasklist = Crontab::$task_list[$pid];
             Crontab::$delay[time() + $sec] = $tasklist["task"];
             $process->write($task);
         }
     });
 }
開發者ID:noikiy,項目名稱:swoole-crontab,代碼行數:22,代碼來源:Process.class.php

示例15: logprint

 * $redirect_stdin_stdout,重定向子進程的標準輸入和輸出。 啟用此選項後,在進程內echo將不是打印屏幕,而是寫入到管道。讀取鍵盤輸入將變為從管道中讀取數據。 默認為阻塞讀取。
 * $create_pipe,是否創建管道,啟用$redirect_stdin_stdout後,此選項將忽略用戶參數,強製為true 如果子進程內沒有進程間通信,可以設置為false
 */
if ($cfg && isset($cfg['muti_process']) && is_array($cfg['muti_process'])) {
    foreach ($cfg['muti_process'] as $proc_cfg) {
        $process = new swoole_process(function (swoole_process $worker) use($proc_cfg) {
            swoole_timer_tick($proc_cfg['ms'], function ($timer_id) use($proc_cfg) {
                $curl = curl_init();
                curl_setopt($curl, CURLOPT_URL, $proc_cfg['url']);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                $data = curl_exec($curl);
                curl_close($curl);
                logprint('info', trim($data));
            });
        }, false, false);
        $pid = $process->start();
        $workers[$pid] = $process;
    }
} else {
    logprint('warn', 'cfg is invaild');
}
master_process($workers);
function logprint($level, $msg)
{
    global $cfg;
    if ($cfg['debug'] == true) {
        echo '[' . date("Y/m/d H:i:s") . '] [' . $level . '] [' . posix_getpid() . '] [' . $msg . ']' . PHP_EOL;
    } else {
        file_put_contents($cfg['logfile'], '[' . date("Y/m/d H:i:s") . '] [' . $level . '] [' . posix_getpid() . '] [' . $msg . ']' . PHP_EOL, FILE_APPEND | LOCK_EX);
    }
}
開發者ID:peterxiemin,項目名稱:commonswoole,代碼行數:31,代碼來源:timer.php


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