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


PHP swoole_server::send方法代码示例

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


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

示例1: my_onReceive

function my_onReceive(swoole_server $serv, $fd, $from_id, $rdata)
{
    $data = unserialize($rdata);
    if (isset($data['cmd'])) {
        switch ($data['cmd']) {
            case 'get':
                $s = microtime(true);
                $res = $serv->taskwait($data, 0.5, 0);
                echo "use " . (microtime(true) - $s) * 1000 . "ms\n";
                $serv->send($fd, PHP_EOL . "get " . $res['key'] . ": " . $res['val']);
                break;
            case "set":
                $serv->task($data, 0);
                $serv->send($fd, "OK\n");
                break;
            case "del":
                $serv->task($data, 0);
                break;
            case "reload":
                break;
            default:
                echo "server:" . $data . PHP_EOL;
        }
    }
}
开发者ID:liangkwok,项目名称:Swoole,代码行数:25,代码来源:shared_server.php

示例2: onReceive

 public function onReceive(swoole_client $cli, $data)
 {
     Trace::debug("*********cli {$this->fd} receive  lenght:" . strlen($data) . ".");
     false !== $this->serv->connection_info($this->fd) && $this->serv->send($this->fd, $this->cryptor->encrypt($data));
     $this->lock = false;
     $this->send();
 }
开发者ID:jinguanio,项目名称:shadowsocks-swoole-php,代码行数:7,代码来源:Client.php

示例3: onReceive

 public function onReceive(swoole_server $server, $fd, $from_id, $data)
 {
     if (empty($data)) {
         // 发送数据给客户端,请求包错误
         $data = array('code' => 500, 'msg' => '非法请求', 'data' => null);
         $server->send($fd, json_encode($data));
     }
     //局域网管理
     $udpClient = $server->connection_info($fd, $from_id);
     if ($udpClient['server_port'] == '9502') {
         $data = str_replace("\r\n\r\n", "", $data);
         switch ($data) {
             case 'stop':
                 echo '服务器关闭: ' . date('Y-m-d H:i:s') . PHP_EOL;
                 $server->shutdown();
                 $server->send($fd, '服务器关闭成功');
                 break;
             case 'reload':
                 echo 'Worker进程重启: ' . date('Y-m-d H:i:s') . PHP_EOL;
                 $server->reload();
                 $server->send($fd, '服务器Worker重启成功');
                 break;
             default:
                 $server->send($fd, '非法请求');
                 break;
         }
     } else {
         $data = json_decode($data, true);
         echo $data['name'] . " say hello " . Test::WORD . "\n";
         $server->send($fd, $data['name'] . " say hello " . Test::WORD);
     }
 }
开发者ID:sukui,项目名称:swoole_auto_reload,代码行数:32,代码来源:server.php

示例4: errorHandler

 function errorHandler()
 {
     if (!empty($this->current_fd)) {
         $rsp = Proxy::shutdown_handler();
         $rsp && $this->serv->send($this->current_fd, $rsp);
     }
 }
开发者ID:liangkwok,项目名称:Swoole,代码行数:7,代码来源:fixed_header_server.php

示例5: onReceive

 public function onReceive(\swoole_server $server, $fd, $from_id, $data)
 {
     $data = trim($data);
     if ($data == 'Stop') {
         //停止
         $server->shutdown();
         $server->send($fd, 'success', $from_id);
     } else {
         if ($data == 'Stats') {
             //状态
             $data = $server->stats();
             $server->send($fd, json_encode($data), $from_id);
         } else {
             if ($data == 'Reload') {
                 //重启
                 $server->reload();
                 $server->send($fd, 'success', $from_id);
             } else {
                 if ($data == 'ResetTelnet') {
                     //重置所有telnet链接
                 } else {
                     $data = json_decode($data, true);
                     if ($data['act'] == 'Telnet' && isset($data['ip']) && isset($data['cmd'])) {
                         //执行命令
                         $service = TelnetEvent::getService($data['ip']);
                         if ($service == null) {
                             $result['code'] = 2;
                         } else {
                             if ($data['cmd'] > 0) {
                                 if (isset($data['arg'])) {
                                     $result['data'] = $service->exec($data['cmd'], $data['arg']);
                                 } else {
                                     $result['data'] = $service->exec($data['cmd']);
                                 }
                                 if ($result == null || $result['data'] == null) {
                                     $result = ['code' => 3];
                                 } else {
                                     $result['code'] = 1;
                                 }
                             } else {
                                 $service->getSwitch()->connect();
                                 if ($service->getSwitch()->isConnect()) {
                                     $result['code'] = 1;
                                 } else {
                                     $result['code'] = 3;
                                 }
                             }
                         }
                         $server->send($fd, json_encode($result), $from_id);
                     } else {
                         $server->send($fd, 'unknown command!', $from_id);
                     }
                 }
             }
         }
     }
     $server->close($fd);
 }
开发者ID:picone,项目名称:SwitchManage,代码行数:58,代码来源:IndexController.class.php

示例6: onReceive

 public function onReceive(swoole_server $serv, $fd, $from_id, $data)
 {
     $info = $serv->connection_info($fd, $from_id);
     if ($info['server_port'] == 9502) {
         $serv->send($fd, "welcom Admin \n");
     } else {
         $serv->send($fd, 'Swoole:' . $data);
     }
 }
开发者ID:alenslan,项目名称:nanshan,代码行数:9,代码来源:multi_port.php

示例7: message

 function message($fd, $code, $msg)
 {
     $this->serv->send($fd, json_encode(array('code' => $code, 'msg' => $msg)));
     echo "[-->{$fd}]\t{$code}\t{$msg}\n";
     if ($code != 0) {
         $this->serv->close($fd);
     }
     return true;
 }
开发者ID:chenwenbin928,项目名称:swoole-src,代码行数:9,代码来源:upload_server.php

示例8: sendResult

 /**
  * 发送回应
  * @param $fd
  * @param $code
  * @param $msg
  * @return bool
  */
 protected function sendResult($fd, $code, $msg)
 {
     $this->serv->send($fd, $this->pack(array('code' => $code, 'msg' => $msg)));
     //打印日志
     if (is_string($msg) and strlen($msg) < 128) {
         echo "[-->{$fd}]\t{$code}\t{$msg}\n";
     }
     //错误时自动关闭连接
     if ($code != 0) {
         $this->serv->close($fd);
     }
     return true;
 }
开发者ID:cjq,项目名称:node-agent,代码行数:20,代码来源:Server.php

示例9: onReceive

 function onReceive($serv, $fd, $from_id, $data)
 {
     if (!isset($this->clients[$fd])) {
         $this->serv->send($fd, "backend server not connected. please try reconnect.");
         $this->serv->close($fd);
     } else {
         echo microtime() . ": client receive\n";
         $backend_socket = $this->clients[$fd]['socket'];
         $backend_socket->send($data);
         echo microtime() . ": send to backend\n";
         echo str_repeat('-', 100) . "\n";
     }
 }
开发者ID:xxoxx,项目名称:gitswoolestudy,代码行数:13,代码来源:proxy.php

示例10: onReceive

 function onReceive($serv, $fd, $from_id, $data)
 {
     //没有空闲的数据库连接
     if (count($this->idle_pool) == 0) {
         //等待队列未满
         if (count($this->wait_queue) < $this->wait_queue_max) {
             $this->wait_queue[] = array('fd' => $fd, 'sql' => $data);
         } else {
             $this->serv->send($fd, "request too many, Please try again later.");
         }
     } else {
         $this->doQuery($fd, $data);
     }
 }
开发者ID:suhanyujie,项目名称:digitalOceanVps,代码行数:14,代码来源:mysqlpool.php

示例11: my_onReceive

function my_onReceive(swoole_server $serv, $fd, $from_id, $data)
{
    //var_dump($serv->connection_info($fd, $from_id));
    //echo "worker_pid=".posix_getpid().PHP_EOL;
    //var_dump($fd, $from_id);
    $serv->send($fd, 'Swoole: ' . $data, $from_id);
}
开发者ID:liangkwok,项目名称:Swoole,代码行数:7,代码来源:udp.php

示例12: on_receive

 /**
  * listen on receive data
  *
  * @param \swoole_server $serv
  * @param $fd
  * @param $from_id
  * @param $data
  */
 public function on_receive(\swoole_server $serv, $fd, $from_id, $data)
 {
     // format passed
     $data = str_replace(self::EOFF, '', $data);
     $data = unserialize($data);
     // check is signal for server shutdown
     if (!empty($data['shutdown']) || !empty($data['reload'])) {
         // try to clear timers
         $this->__clear_timer();
         $send = !empty($data['shutdown']) ? $serv->shutdown() : $serv->reload();
         $send = serialize($send);
         $send .= self::EOFF;
         $ends = $serv->send($fd, $send);
         if ($ends) {
             $serv->close($fd);
         }
         return;
     }
     // dont send back
     if (!empty($data['return']) && $data['return'] === FALSE) {
         $back = serialize(TRUE);
         $back .= self::EOFF;
         $serv->send($fd, $back);
         $serv->close($fd);
     }
     // now post data to a task
     $param = ['fd' => $fd, 'data' => $data];
     $param = serialize($param);
     $param .= self::EOFF;
     // worker direct
     $this->on_task($serv, NULL, NULL, $param);
     return;
 }
开发者ID:lanlin,项目名称:codeigniter-swoole,代码行数:41,代码来源:Server.php

示例13: onReceive

 function onReceive(swoole_server $serv, $fd, $reactor_id, $data)
 {
     $op = strtolower(strstr($data, ' ', true));
     //出队
     if ($op == 'pop') {
         if ($this->head_index >= $this->tail_index) {
             $serv->send($fd, 'ERR empty' . self::EOF);
             return;
         }
         $result = $this->leveldb->get('data_' . $this->head_index);
         if ($result) {
             $this->leveldb->delete('data_' . $this->head_index);
             $this->head_index++;
             $this->pop_count++;
             $this->leveldb->set('_head_index', $this->head_index);
             $serv->send($fd, 'OK ' . $result . self::EOF);
         } else {
             $serv->send($fd, 'ERR get() failed.' . self::EOF);
         }
     } elseif ($op == 'push') {
         $result = $this->leveldb->set('data_' . $this->tail_index, substr($data, 5, strlen($data) - 5 - strlen(self::EOF)));
         if ($result) {
             $this->tail_index++;
             $this->push_count++;
             $this->leveldb->set('_tail_index', $this->tail_index);
             $serv->send($fd, 'OK ' . self::EOF);
         } else {
             $serv->send($fd, 'ERR write to leveldb failed.' . self::EOF);
         }
     } elseif ($op == 'stats') {
         $serv->send($fd, 'OK ' . var_export(['head_index' => $this->head_index, 'tail_index' => $this->tail_index, 'push_count' => $this->push_count, 'pop_count' => $this->pop_count], true) . self::EOF);
     } else {
         $serv->send($fd, 'ERR unsupported command [' . $op . ']' . self::EOF);
     }
 }
开发者ID:xingcuntian,项目名称:php-queue,代码行数:35,代码来源:Server.php

示例14: sendResult

 /**
  * 发送回应
  * @param $fd
  * @param $code
  * @param $msg
  * @return bool
  */
 protected function sendResult($fd, $code, $msg, $data = null)
 {
     $array = array('code' => $code, 'msg' => $msg);
     if ($data) {
         $array['data'] = $data;
     }
     $this->serv->send($fd, $this->pack($array));
     //打印日志
     if (is_string($msg) and strlen($msg) < 128) {
         echo "[-->{$fd}]\t{$this->currentCommand}\t{$code}\t{$msg}\n";
     }
     //        //错误时自动关闭连接
     //        if ($code != 0)
     //        {
     //            $this->serv->close($fd);
     //        }
     return true;
 }
开发者ID:FrankWebDev,项目名称:node-agent,代码行数:25,代码来源:Server.php

示例15: onReceive

 public function onReceive(swoole_server $serv, $fd, $from_id, $data)
 {
     echo "Get Message From Client {$fd}:{$data}\n";
     foreach ($serv->connections as $client) {
         if ($fd != $client) {
             $serv->send($client, $data);
         }
     }
 }
开发者ID:jinchunguang,项目名称:swoole-doc,代码行数:9,代码来源:chat_server.php


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