本文整理汇总了PHP中swoole_process类的典型用法代码示例。如果您正苦于以下问题:PHP swoole_process类的具体用法?PHP swoole_process怎么用?PHP swoole_process使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了swoole_process类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: 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
示例2: 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:jinguanio,项目名称:swoolecrawler,代码行数:26,代码来源:server.php
示例3: 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
示例4: start
/**
* @brief 启动子进程
* @param \swoole_process $worker
*/
public function start(\swoole_process $worker)
{
$this->_worker = $worker;
swoole_event_add($worker->pipe, function ($pipe) use($worker) {
echo $worker->read() . PHP_EOL;
});
$this->worker();
}
开发者ID:vucms,项目名称:aha,代码行数:12,代码来源:Asyncworker.php
示例5: callback_vmstat
/**
* swoole_process回调函数
* @param swoole_process $worker
*/
function callback_vmstat(swoole_process $worker)
{
global $table;
$vmstat = $table->get('vmstat');
$cmd = $vmstat['cmd'];
$interval = $vmstat['interval'];
$count = $vmstat['count'];
$worker->exec($cmd, array($interval, $count));
}
开发者ID:stonegithubs,项目名称:swoole-vmstat,代码行数:13,代码来源:server.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: callback_function
function callback_function(swoole_process $worker)
{
//echo "Worker: start. PID=".$worker->pid."\n";
//recv data from master
$recv = $worker->pop();
echo "From Master: {$recv}\n";
sleep(2);
$worker->exit(0);
}
开发者ID:chenwenbin928,项目名称:swoole-src,代码行数:9,代码来源:msgqueue.php
示例8: callback_function
function callback_function(swoole_process $worker)
{
echo "Worker: start. PID=" . $worker->pid . "\n";
//recv data from master
$recv = $worker->read();
echo "From Master: {$recv}\n";
//send data to master
$worker->write("hello master\n");
sleep(2);
$worker->exit(0);
}
开发者ID:vkey24,项目名称:crazy-grab,代码行数:11,代码来源:worker.php
示例9: callback_process_function
function callback_process_function(swoole_process $worker)
{
set_time_limit(300);
$task = json_decode($worker->read(), true);
$worker->name('crontab.php worker=' . $task['uniqid']);
$Handle = new TimingCall_Handle($task);
$Handle->upNextExecuteTime();
$Handle->refreshStatistics();
$Handle->Execute();
$worker->exit(0);
}
开发者ID:imdaqian,项目名称:Hi-Timed,代码行数:11,代码来源:cmd.php
示例10: 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
示例11: 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
示例12: callback_function
function callback_function(swoole_process $worker)
{
//echo "Worker: start. PID=".$worker->pid."\n";
//recv data from master
$cnt = 0;
while ($cnt < 2) {
// 如果队列里没有数据,则pop方法阻塞等待
$recv = $worker->pop();
echo "From Master: {$recv}\n";
$cnt++;
}
sleep(1);
$worker->exit(0);
}
开发者ID:silentred,项目名称:learning-path,代码行数:14,代码来源:queue.php
示例13: readPipe
/**
* @brief 读取管道中的消息包体
* @param \swoole_process $process
*/
public function readPipe(\swoole_process $process)
{
while (false !== ($content = $process->read())) {
if (false === $content) {
\Aha\Log\Sys::log()->error(array('IPC_PIPE_READ_ERR' => $content));
break;
} else {
$this->append($content);
}
if (strlen($content) < 8191) {
break;
}
}
}
开发者ID:eyehere,项目名称:aha,代码行数:18,代码来源:Package.php
示例14: child_async
function child_async(swoole_process $worker)
{
//echo "Worker: start. PID=".$worker->pid."\n";
//recv data from master
$GLOBALS['worker'] = $worker;
global $argv;
$worker->name("{$argv[0]}: worker");
swoole_process::signal(SIGTERM, function ($signal_num) use($worker) {
echo "signal call = {$signal_num}, #{$worker->pid}\n";
});
swoole_event_add($worker->pipe, function ($pipe) use($worker) {
$recv = $worker->read();
echo "From Master: {$recv}\n";
$worker->write("hello master\n");
});
}
开发者ID:stonegithubs,项目名称:swoole-game,代码行数:16,代码来源:server.php
示例15: master_process
function master_process($workers)
{
//监听子进程,如果停止,会再拉起来
swoole_process::signal(SIGCHLD, function ($signo) use(&$workers) {
while (1) {
$ret = swoole_process::wait(false);
if ($ret) {
$pid = $ret['pid'];
//这里实现一个自动拉起的能力
$child_process = $workers[$pid];
logprint('info', "Worker Exit, kill_signal={$ret['signal']} PID=" . $pid);
$new_pid = $child_process->start();
$workers[$new_pid] = $child_process;
unset($workers[$pid]);
} else {
break;
}
}
});
//kill -10 结束全部程序
swoole_process::signal(SIGUSR1, function ($signo) use(&$workers) {
swoole_process::signal(SIGCHLD, null);
foreach ($workers as $pid => $worker) {
swoole_process::kill($pid);
}
//处理子进程,然后自己退出
exit;
});
}
开发者ID:peterxiemin,项目名称:commonswoole,代码行数:29,代码来源:timer.php
示例16: register_signal
public static function register_signal()
{
swoole_process::signal(SIGUSR2, function ($signal_num) {
echo "收到结束信号,结束进程\n";
exit;
});
}
开发者ID:stonegithubs,项目名称:squire,代码行数:7,代码来源:Squire_Gearman.class.php
示例17: 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
示例18: 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
示例19: 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
示例20: 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
注:本文中的swoole_process类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论