当前位置: 首页>>代码示例>>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;未经允许,请勿转载。