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


PHP swoole_process::read方法代码示例

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


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

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

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

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

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

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

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

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

示例10: onTmpProcess

 public function onTmpProcess(swoole_process $worker)
 {
     $cmd = $worker->read();
     $handle = popen($cmd, 'r');
     swoole_event_add($worker->pipe, function () use($worker, $handle) {
         $cmd = $worker->read();
         if ($cmd == 'exit') {
             $worker->exit();
         }
         fwrite($handle, $cmd);
     });
     while (!feof($handle)) {
         $buffer = fread($handle, 18192);
         echo $buffer;
     }
 }
开发者ID:jinchunguang,项目名称:swoole-doc,代码行数:16,代码来源:shell_server.php

示例11: callback_vmstat

 * websocket server配置
 */
$server->set(array('worker_num' => 1, 'daemonize' => false, 'max_request' => 1000, 'dispatch_mode' => 1));
/**
 * websocket server start
 * 成功后回调
 */
$server->on('start', function ($serv) use($_maxMasterPidLength, $_maxManagerPidLength, $_maxWorkerIdLength, $_maxWorkerPidLength) {
    echo "[1A\n[K-----------------------[47;30m SWOOLE [0m-----------------------------\n[0m";
    echo 'swoole version:' . swoole_version() . "          PHP version:" . PHP_VERSION . "\n";
    echo "------------------------[47;30m WORKERS [0m---------------------------\n";
    echo "[47;30mMasterPid[0m", str_pad('', $_maxMasterPidLength + 2 - strlen('MasterPid')), "[47;30mManagerPid[0m", str_pad('', $_maxManagerPidLength + 2 - strlen('ManagerPid')), "[47;30mWorkerId[0m", str_pad('', $_maxWorkerIdLength + 2 - strlen('WorkerId')), "[47;30mWorkerPid[0m", str_pad('', $_maxWorkerPidLength + 2 - strlen('WorkerPid')), "\n";
    global $process;
    //将process->pipe加入到swoole的reactor事件监听中
    swoole_event_add($process->pipe, function ($pipe) use($process, $serv) {
        $str = $process->read();
        $conn_list = $serv->connection_list();
        if (!empty($conn_list)) {
            foreach ($conn_list as $fd) {
                $serv->push($fd, $str);
            }
        }
    });
});
/**
 * swoole_process回调函数
 * @param swoole_process $worker
 */
function callback_vmstat(swoole_process $worker)
{
    global $table;
开发者ID:stonegithubs,项目名称:swoole-vmstat,代码行数:31,代码来源:server.php

示例12: process

//创建的进程数
$finished = false;
$lock = new swoole_lock(SWOOLE_MUTEX);
for ($i = 0; $i < $worker_num; $i++) {
    $process = new swoole_process('process');
    //$process->useQueue();
    $pid = $process->start();
    $workers[$pid] = $process;
}
foreach ($workers as $pid => $process) {
    //子进程也会包含此事件
    swoole_event_add($process->pipe, function ($pipe) use($process, $lock, &$finished) {
        $lock->lock();
        if (!$finished) {
            $finished = true;
            $data = $process->read();
            echo "RECV: " . $data . PHP_EOL;
        }
        $lock->unlock();
    });
}
function process(swoole_process $process)
{
    $response = 'http response';
    $process->write($response);
    echo $process->pid, "\t", $process->callback . PHP_EOL;
}
for ($i = 0; $i < $worker_num; $i++) {
    $ret = swoole_process::wait();
    $pid = $ret['pid'];
    echo "Worker Exit, PID=" . $pid . PHP_EOL;
开发者ID:silentred,项目名称:learning-path,代码行数:31,代码来源:swoole_process.php

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

示例14: dosomething

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);
            }
        }
    });
}
//开启子进程进行异步处理
function callback_function(swoole_process $worker)
{
    $GLOBALS['worker'] = $worker;
    swoole_event_add($worker->pipe, function ($pipe) {
开发者ID:xingcuntian,项目名称:ssos,代码行数:31,代码来源:test_process.php

示例15: function

    echo "#{$server->worker_id} message from #{$src_worker_id}: {$data}\n";
});
$server->on('task', function ($server, $task_id, $from_id, $data) {
    var_dump($task_id, $from_id, $data);
});
$server->on('finish', function ($server, $fd, $from_id) {
});
$server->on('receive', function (swoole_server $server, $fd, $from_id, $data) {
    if (trim($data) == 'task') {
        $server->task("async task coming");
    } else {
        $worker_id = 1 - $server->worker_id;
        $server->sendMessage("hello task process", $worker_id);
    }
});
$server->start();
$server = new swoole_server('127.0.0.1', 9501);
$process = new swoole_process(function ($process) use($server) {
    while (true) {
        $msg = $process->read();
        foreach ($server->connections as $conn) {
            $server->send($conn, $msg);
        }
    }
});
$server->addProcess($process);
$server->on('receive', function ($serv, $fd, $from_id, $data) use($process) {
    //群发收到的消息
    $process->write($data);
});
$server->start();
开发者ID:xiangdong1987,项目名称:AllInOne,代码行数:31,代码来源:test.php


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