當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。