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


PHP swoole_process::write方法代码示例

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


在下文中一共展示了swoole_process::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: child_sync

function child_sync(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:zzjin,项目名称:swoole-src,代码行数:11,代码来源:worker.php

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: callback_function

<?php

$process = new swoole_process('callback_function', true);
$pid = $process->start();
function callback_function(swoole_process $worker)
{
    $worker->exec('/usr/local/bin/php', array(__DIR__ . '/stdin_stdout.php'));
}
echo "From Worker: " . $process->read();
$process->write("hello worker\n");
echo "From Worker: " . $process->read();
$ret = swoole_process::wait();
var_dump($ret);
开发者ID:noikiy,项目名称:swoole-src,代码行数:13,代码来源:exec.php

示例9: process

function process(swoole_process $process)
{
    $response = 'http response';
    $process->write($response);
    echo $process->pid, "\t", $process->callback . PHP_EOL;
}
开发者ID:silentred,项目名称:learning-path,代码行数:6,代码来源:swoole_process.php

示例10: pyhon_process

<?php

$process = new swoole_process('pyhon_process', true);
$pid = $process->start();
function pyhon_process(swoole_process $worker)
{
    $worker->exec('/usr/bin/python', array("echo.py"));
}
$process->write("hello world\n");
echo $process->read();
$ret = swoole_process::wait();
var_dump($ret);
开发者ID:liangkwok,项目名称:Swoole,代码行数:12,代码来源:python.php

示例11: dosomething

    } else {
        return false;
    }
}
function dosomething($data)
{
    //具体要子进程处理的逻辑 如果这里的处理时间越长,使用多进程处理会越显优势
    sleep(2);
    return 1;
}
//启动4个进程进行处理
$worker_num = 4;
for ($i = 0; $i < $worker_num; $i++) {
    $process = new swoole_process('callback_function', false, true);
    $pid = $process->start();
    $process->write(dotest());
    $process->pid = $pid;
    // $workers[$pid] = $process;
    swoole_event_add($process->pipe, function ($pipe) use($process) {
        $recv = $process->read();
        if ($recv != '') {
            $data = dotest();
            if ($data != false) {
                $process->write($data);
            } else {
                swoole_process::kill($process->pid);
            }
        }
    });
}
//开启子进程进行异步处理
开发者ID:xingcuntian,项目名称:ssos,代码行数:31,代码来源:test_process.php

示例12: while

    global $workers;
    $worker = $workers[$pipe];
    $data = $worker->read();
    if ($data == false) {
        //表示子进程已关闭,回收它
        $status = swoole_process::wait();
        echo "Worker#{$status['pid']} exit\n";
    } else {
        echo "RECV: " . $data;
    }
}
//循环创建进程
for ($i = 0; $i < $worker_num; $i++) {
    $process = new swoole_process(function (swoole_process $process) {
        $i = 1;
        while ($i++) {
            $process->write("Worker#{$process->id}: hello master\n");
            if ($i > 5 and $process->id == 1) {
                $process->exit();
            }
            sleep(1);
        }
    });
    $process->id = $i;
    $pid = $process->start();
    $workers[$process->pipe] = $process;
}
//将子进程的管道加入EventLoop
foreach ($workers as $process) {
    swoole_event_add($process->pipe, 'onReceive');
}
开发者ID:sophia2152,项目名称:swoole-src,代码行数:31,代码来源:async_master.php

示例13: process_run

{
    $binpath = $_SERVER["_"];
    $worker->exec($binpath, array(ROOT_PATH . "http_test.php", $worker->pipe));
}
$process = new swoole_process("fork");
$process->start();
function process_run($worker)
{
    echo "abc\n";
    $worker->exit(0);
    exit;
}
function create_process()
{
    $process = new swoole_process("process_run");
    $process->start();
}
swoole_timer_add(1000, function ($interval) {
    create_process();
    create_process();
});
swoole_process::signal(SIGCHLD, function ($signo) {
    while ($pid = pcntl_wait($status, WNOHANG)) {
        echo $pid . "\n";
    }
});
swoole_event_add($process->pipe, function ($pipe) use($process) {
    $ret = $process->read();
    echo $ret;
    $process->write($ret);
});
开发者ID:jymsy,项目名称:swoole-crontab,代码行数:31,代码来源:process_test.php

示例14: params_http

 /**
  * 开启http服务 web api
  * @param $opt
  */
 public static function params_http($opt)
 {
     if (!isset($opt["http"])) {
         return false;
     }
     if (isset($opt["host"]) && $opt["host"]) {
         self::$host = $opt["host"];
     }
     if (isset($opt["port"]) && $opt["port"]) {
         self::$port = $opt["port"];
     }
     $process = new swoole_process(array(new Main(), "http_run"));
     $process->start();
     self::$http_server = $process;
     swoole_event_add($process->pipe, function ($pipe) use($process) {
         $manager = new Manager();
         $recv = $process->read();
         $recv = explode("#@#", $recv);
         $function = $recv[0] . "_cron";
         $process->write(json_encode($manager->{$function}(json_decode($recv[1], true))));
     });
     return true;
 }
开发者ID:liumingzhij26,项目名称:swoole-crontab,代码行数:27,代码来源:main.php

示例15: callback_function

<?php

$redirect_stdout = true;
$process = new swoole_process('callback_function', $redirect_stdout);
$worker_pid = $process->start();
echo "new worker,PID=" . $worker_pid . PHP_EOL;
function callback_function($worker)
{
    echo "workerstart PID=" . $worker->pid . "\n";
    sleep(2);
    $worker->write("hello world!\n");
    $recv = $worker->read();
    echo "worker receive : {$recv} \n";
    $worker->exit(0);
}
$ret = swoole_process::wait();
var_dump($ret);
echo "Master Receive:\n" . $process->read() . PHP_EOL;
$process->write("master");
$ret = swoole_process::wait();
var_dump($ret);
sleep(2);
开发者ID:vkey24,项目名称:crazy-grab,代码行数:22,代码来源:process.php


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