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


PHP swoole_client::recv方法代碼示例

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


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

示例1: onPacket

 function onPacket($sock)
 {
     $data = $this->centerSocket->recv();
     $req = unserialize($data);
     if (empty($req['cmd'])) {
         $this->log("error packet");
         return;
     }
     if ($req['cmd'] == 'getInfo') {
         $this->centerSocket->send(serialize(['cmd' => 'putInfo', 'info' => ['hostname' => gethostname(), 'ipList' => swoole_get_local_ip(), 'uname' => php_uname(), 'version' => self::VERSION, 'deviceInfo' => ['cpu' => self::getCpuInfo(), 'mem' => self::getMemInfo(), 'disk' => self::getDiskInfo()]]]));
     } elseif ($req['cmd'] == 'upgrade') {
         if (empty($req['url']) or empty($req['hash'])) {
             $this->log("缺少URL和hash");
         }
         $file = self::downloadPackage($req['url']);
         if ($file) {
             $hash = md5($file);
             //hash對比一致,可以更新
             if ($hash == $req['hash']) {
                 //更新phar包
                 file_put_contents($this->pharFile, $file);
                 $this->log("upgrade to " . $req['version']);
                 //退出進程,等待重新拉起
                 exit;
             }
         } else {
             $this->log("upgrade failed. Cannot fetch url [{$req['url']}]");
         }
     }
 }
開發者ID:FrankWebDev,項目名稱:node-agent,代碼行數:30,代碼來源:Node.php

示例2: dbcp_query

function dbcp_query($sql)
{
    $link = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
    //TCP方式、同步
    $link->connect('127.0.0.1', 55151);
    //連接
    $link->send($sql);
    //執行查詢
    die(var_dump($link->recv()));
    return unserialize($link->recv());
    //這行會報錯,注釋掉了:PHP Notice:  unserialize(): Error at offset 0 of 292 bytes in /data/htdocs/mysql.swoole.com/mysqlSwooleCli.php on line 6
    //swoole_client類析構時會自動關閉連接
}
開發者ID:suhanyujie,項目名稱:digitalOceanVps,代碼行數:13,代碼來源:mysqlClient.php

示例3: client

 /**
  * connect to swoole server then send data
  *
  * @return string
  */
 public static function client()
 {
     $return = FALSE;
     $client = new \swoole_client(SWOOLE_SOCK_TCP);
     // set eof charactor
     $client->set(['open_eof_split' => TRUE, 'package_eof' => self::EOFF]);
     // listen on
     $client->on('connect', '\\CI_Swoole\\Client::on_connect');
     $client->on('receive', '\\CI_Swoole\\Client::on_receive');
     $client->on('error', '\\CI_Swoole\\Client::on_error');
     $client->on('close', '\\CI_Swoole\\Client::on_close');
     // connect
     $client->connect(self::HOST, self::PORT, 10);
     // send data
     if ($client->isConnected()) {
         $post = serialize(static::$post);
         $post .= self::EOFF;
         $issend = $client->send($post);
     }
     // receiv data
     if (isset($issend) && $issend) {
         $return = @$client->recv();
         $return = str_replace(self::EOFF, '', $return);
         $return = unserialize($return);
     }
     $client->close();
     unset($client);
     return $return;
 }
開發者ID:lanlin,項目名稱:codeigniter-swoole,代碼行數:34,代碼來源:Client.php

示例4: query

 public static function query($sql)
 {
     $client = new \swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
     $client->connect('127.0.0.1', 9509, 0.5, 0);
     $client->send($sql);
     return $client->recv();
 }
開發者ID:kcloze,項目名稱:ycf,代碼行數:7,代碼來源:ModelProxyDb.php

示例5: recv

 public function recv()
 {
     $data = $this->socket->recv();
     if ($data === false) {
         echo "Error: {$this->socket->errMsg}";
         return false;
     }
     $this->buffer .= $data;
     $recv_data = $this->parseData($this->buffer);
     if ($recv_data) {
         $this->buffer = '';
         return $recv_data;
     } else {
         return false;
     }
 }
開發者ID:viile,項目名稱:swoole-src,代碼行數:16,代碼來源:WebSocketClient.php

示例6: test_client

function test_client()
{
    $client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
    //同步阻塞
    if (!$client->connect('127.0.0.1', 10000)) {
        exit("connect fail\n");
    }
    if (empty($argv[1])) {
        $loop = 1;
    } else {
        $loop = intval($argv[1]);
    }
    for ($i = 0; $i < $loop; $i++) {
        $client->send(str_repeat("A", 600) . $i);
        $data = $client->recv(7000, 0);
        if ($data === false) {
            echo "recv fail\n";
            break;
        }
        //echo "recv[$i]",$data,"\n";
    }
    //echo "len=".strlen($data)."\n";
    // $client->send("HELLO\0\nWORLD");
    // $data = $client->recv(9000, 0);
    $client->close();
    var_dump($data);
    unset($client);
}
開發者ID:xxoxx,項目名稱:gitswoolestudy,代碼行數:28,代碼來源:cli.php

示例7: sendData

 /**
  * 發送數據
  * @param string $data
  * @return unknown
  */
 public function sendData($data)
 {
     if (empty($this->client)) {
         $this->client = new \swoole_client(SWOOLE_SOCK_TCP);
     }
     if (!$this->client->connect($this->ip, $this->port, -1)) {
         exit("connect failed. Error: {$this->client->errCode}\n");
     }
     if (\is_array($data) || \is_object($data)) {
         $data = \json_encode($data);
     }
     $data = StringUtil::encryStr($data, ApiConfig::ENCRYTP_DECRYPT_SALT);
     $this->client->send($data);
     $result = $this->client->recv();
     return StringUtil::decryStr($result, ApiConfig::ENCRYTP_DECRYPT_SALT);
 }
開發者ID:zgoubaophp,項目名稱:boytemptapi,代碼行數:21,代碼來源:ApiClient.php

示例8: pop

 function pop()
 {
     if ($this->client->send("POP " . self::EOF)) {
         $result = $this->client->recv();
         if ($result === false) {
             return false;
         }
         if (substr($result, 0, 2) == 'OK') {
             return substr($result, 3, strlen($result) - 3 - strlen(self::EOF));
         } else {
             $this->errMsg = substr($result, 4);
             return false;
         }
     } else {
         return false;
     }
 }
開發者ID:xingcuntian,項目名稱:php-queue,代碼行數:17,代碼來源:Client.php

示例9: clientAction

 public function clientAction()
 {
     $client = new swoole_client(SWOOLE_SOCK_TCP);
     $client->connect('192.168.80.140', 9021, 0.5);
     $client->send('hello world!');
     echo $client->recv();
     $client->close();
     return false;
 }
開發者ID:zhangjingpu,項目名稱:yaf-lib,代碼行數:9,代碼來源:Swoole.php

示例10: __construct

 public function __construct()
 {
     $client = new swoole_client(SWOOLE_SOCK_UDP);
     //默認是同步,第二個參數可以選填異步
     //發起網絡連接
     $client->connect('0.0.0.0', 9504, 0.5);
     $client->send('demo');
     echo $client->recv();
 }
開發者ID:jhomephper,項目名稱:phalcon_swoole,代碼行數:9,代碼來源:UdpSocketClient.php

示例11: onReceive

 function onReceive($serv, $fd, $from_id, $data)
 {
     $socket = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
     if ($socket->connect('127.0.0.1', 8002, 0.5)) {
         $socket->send($data);
         $serv->send($fd, $socket->recv(8192, 0));
     }
     //unset($socket);
     $serv->close($fd);
 }
開發者ID:jinguanio,項目名稱:david,代碼行數:10,代碼來源:proxy_sync.php

示例12: sendToServer

function sendToServer($str)
{
    global $server;
    $client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
    if (!$client->connect($server['ip'], $server['port'], -1)) {
        exit("connect failed. Error: {$client->errCode}\n");
    }
    $client->send($str);
    $str = $client->recv();
    $client->close();
    return $str;
}
開發者ID:dormscript,項目名稱:dataTransfer,代碼行數:12,代碼來源:handleQueue.php

示例13: thread_start

function thread_start(swoole_thread $coroutine)
{
    $serv = $coroutine->serv;
    $data = $serv->recv($fd);
    $socket = new swoole_client(SWOOLE_SOCK_TCP);
    if ($socket->connect('127.0.0.1', 9502, 0.5)) {
        $socket->send("request\n");
        $response = $socket->recv();
    }
    $socket->close();
    $serv->send($fd, "Server: {$response}\n");
}
開發者ID:liangkwok,項目名稱:Swoole,代碼行數:12,代碼來源:coroutine.php

示例14: multiRequest

/**
 * 批量請求
 * @param array $request_buffer_array ['ip:port'=>req_buf, 'ip:port'=>req_buf, ...]
 * @return multitype:unknown string
 */
function multiRequest($request_buffer_array)
{
    \Statistics\Lib\Cache::$lastSuccessIpArray = array();
    $client_array = $sock_to_ip = $ip_list = array();
    foreach ($request_buffer_array as $address => $buffer) {
        list($ip, $port) = explode(':', $address);
        $ip_list[$ip] = $ip;
        $client = new swoole_client(SWOOLE_TCP | SWOOLE_KEEP, SWOOLE_SOCK_SYNC);
        $client->connect($ip, $port);
        if (!$client) {
            continue;
        }
        $client_array[$address] = $client;
        $client_array[$address]->send(encode($buffer));
        $sock_to_address[(int) $client->sock] = $address;
    }
    $read = $client_array;
    $write = $except = $read_buffer = array();
    $time_start = microtime(true);
    $timeout = 0.99;
    // 輪詢處理數據
    while (count($read) > 0) {
        foreach ($read as $client) {
            $address = $sock_to_address[(int) $client->sock];
            $buf = $client->recv();
            if (!$buf) {
                unset($client_array[$address]);
                continue;
            }
            if (!isset($read_buffer[$address])) {
                $read_buffer[$address] = $buf;
            } else {
                $read_buffer[$address] .= $buf;
            }
            // 數據接收完畢
            if (($len = strlen($read_buffer[$address])) && $read_buffer[$address][$len - 1] === "\n") {
                unset($client_array[$address]);
            }
        }
        // 超時了
        if (microtime(true) - $time_start > $timeout) {
            break;
        }
        $read = $client_array;
    }
    foreach ($read_buffer as $address => $buf) {
        list($ip, $port) = explode(':', $address);
        \Statistics\Lib\Cache::$lastSuccessIpArray[$ip] = $ip;
    }
    \Statistics\Lib\Cache::$lastFailedIpArray = array_diff($ip_list, \Statistics\Lib\Cache::$lastSuccessIpArray);
    ksort($read_buffer);
    return $read_buffer;
}
開發者ID:smalleyes,項目名稱:statistics,代碼行數:58,代碼來源:functions.php

示例15: testSwoole

 public function testSwoole()
 {
     $this->assertTrue(in_array('swoole', get_loaded_extensions()), '缺少swoole extension');
     $cfg = (include ROOT_PATH . '/../config/sysconfig.php');
     $params = array('ip', 'port');
     foreach ($params as $param) {
         $this->assertTrue(array_key_exists($param, $cfg['swooleConfig']) && !empty($cfg['swooleConfig'][$param]), 'swoole缺少' . $param . '配置');
     }
     // 測試連接
     $swoole = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
     $this->assertTrue($swoole->connect($cfg['swooleConfig']['ip'], $cfg['swooleConfig']['port']), 'swoole連接失敗');
     // 測試swoole數據傳輸
     $this->assertTrue($swoole->send(json_encode(array('cmd' => 'checkMobi', 'args' => 18611740380.0))), 'swoole send失敗');
     $this->assertTrue(!empty($swoole->recv()), 'swoole recv失敗');
 }
開發者ID:nicklos17,項目名稱:appserver,代碼行數:15,代碼來源:ServerTest.php


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