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


PHP swoole_client::send方法代碼示例

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


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

示例1: sendtagbyswoole

 /**
  * send message by swoole
  * @param string $content the command
  * return boolean true if shut down the swoole_client successfully
  */
 private function sendtagbyswoole($content)
 {
     $client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
     $client->connect('127.0.0.1', 8888, 0.5, 0);
     $client->send($content);
     return $client->close();
 }
開發者ID:CptSteven,項目名稱:faster-rcnn-mod,代碼行數:12,代碼來源:train.php

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

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

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

示例7: run

 public function run(Promise &$promise)
 {
     $cli = new \swoole_client(SWOOLE_TCP, SWOOLE_SOCK_ASYNC);
     $urlInfo = parse_url($this->url);
     $timeout = $this->timeout;
     if (!isset($urlInfo['port'])) {
         $urlInfo['port'] = 80;
     }
     $httpParser = new \HttpParser();
     $cli->on("connect", function ($cli) use($urlInfo, &$timeout, &$promise) {
         $cli->isConnected = true;
         $host = $urlInfo['host'];
         if ($urlInfo['port']) {
             $host .= ':' . $urlInfo['port'];
         }
         $req = array();
         $req[] = "GET {$this->url} HTTP/1.1\r\n";
         $req[] = "User-Agent: PHP swAsync\r\n";
         $req[] = "Host:{$host}\r\n";
         $req[] = "Connection:close\r\n";
         $req[] = "\r\n";
         $req = implode('', $req);
         $cli->send($req);
     });
     $cli->on("receive", function ($cli, $data = "") use(&$httpParser, &$promise) {
         $ret = $httpParser->execute($data);
         if ($ret !== false) {
             Timer::del($cli->sock);
             $cli->isDone = true;
             if ($cli->isConnected()) {
                 $cli->close();
             }
             $promise->accept(['http_data' => $ret]);
         }
     });
     $cli->on("error", function ($cli) use(&$promise) {
         Timer::del($cli->sock);
         $promise->accept(['http_data' => null, 'http_error' => 'Connect error']);
     });
     $cli->on("close", function ($cli) use(&$promise) {
     });
     if ($this->proxy) {
         $cli->connect($this->proxy['host'], $this->proxy['port'], 0.05);
     } else {
         $cli->connect($urlInfo['host'], $urlInfo['port'], 0.05);
     }
     $cli->isConnected = false;
     if (!$cli->errCode) {
         Timer::add($cli->sock, $this->timeout, function () use($cli, &$promise) {
             @$cli->close();
             if ($cli->isConnected) {
                 $promise->accept(['http_data' => null, 'http_error' => 'Http client read timeout']);
             } else {
                 $promise->accept(['http_data' => null, 'http_error' => 'Http client connect timeout']);
             }
         });
     }
 }
開發者ID:zhanglei,項目名稱:swPromise,代碼行數:58,代碼來源:HttpClientFuture.class.php

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

示例9: send

function send(swoole_client $cli)
{
    $data = array('str1' => str_repeat('A', rand(1000, 9000)), 'str2' => str_repeat('B', rand(1000, 9000)), 'str3' => str_repeat('C', rand(1000, 9000)));
    $data['int1'] = rand(100000, 999999);
    $sendStr = serialize($data);
    $sendData = pack('N', strlen($sendStr)) . $sendStr;
    $cli->send($sendData);
    echo "send length=" . strlen($sendData) . ", SerId={$data['int1']}\n";
}
開發者ID:pangudashu,項目名稱:swoole-src,代碼行數:9,代碼來源:async_client.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: send_chunk

/**
 * 分段發送數據
 *
 * @param swoole_client $client
 * @param string        $data
 * @param int           $chunk_size
 */
function send_chunk(swoole_client $client, $data, $chunk_size = 1024)
{
    $len = strlen($data);
    $chunk_num = intval($len / $chunk_size) + 1;
    for ($i = 0; $i < $chunk_num; $i++) {
        if ($len < ($i + 1) * $chunk_size) {
            $sendn = $len - $i * $chunk_size;
        } else {
            $sendn = $chunk_size;
        }
        $client->send(substr($data, $i * $chunk_size, $sendn));
    }
}
開發者ID:sophia2152,項目名稱:swoole-src,代碼行數:20,代碼來源:client.php

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


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