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


PHP swoole_server::connection_info方法代码示例

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


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

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

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

示例3: onConnect

 public function onConnect(swoole_server $serv, $fd, $from_id)
 {
     //获取连接的客户端信息
     $fdInfo = $serv->connection_info($fd);
     echo '<pre>';
     print_r($fdInfo);
     echo '</pre>';
     $serv->send($fd, "Welcome {$fd} Connect Server");
 }
开发者ID:stonegithubs,项目名称:swoole-game,代码行数:9,代码来源:server.php

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

示例5: onPackage

 /**
  * @param $serv
  * @param $fd
  * @param $from_id
  * @param $data
  */
 function onPackage(\swoole_server $serv, $fd, $from_id, $data)
 {
     $conn = $serv->connection_info($fd, $from_id);
     if ($conn['from_port'] == self::SVR_PORT_LOG) {
         $pkg = unpack('Nmodule_id/Ninterface_id/Nspecial_id/Nuser_id/Clevel/Ntime', $data);
         if ($pkg == false) {
             $this->log("error package. data" . $data);
             return;
         }
         $pkg['client_ip'] = $conn['remote_ip'];
         $pkg['txt'] = substr($data, 21);
         $tmp = $pkg;
         $tmp['cmd'] = 'server';
         $this->cli->send(json_encode($tmp));
         $this->redis->sAdd($pkg['module_id'] . "_" . $pkg['interface_id'], $pkg['client_ip']);
         if (time() >= strtotime($this->tomorrow . ' ' . '00:00:00')) {
             $this->log_table = 'logs_' . $this->tomorrow;
         }
         table($this->log_table)->put($pkg);
     }
 }
开发者ID:google2013,项目名称:StatsCenter,代码行数:27,代码来源:LogSvr.php

示例6: onReceive

 function onReceive(\swoole_server $serv, $fd, $from_id, $data)
 {
     $this->fd = $fd;
     $_key = explode(' ', trim($data));
     if (count($_key) != 3) {
         return;
     }
     //模调系统,自动创建接口
     if ($_key[0] == 'GET') {
         $this->clientInfo = $serv->connection_info($fd);
         $key = $this->getInterfaceId($_key[1], $_key[2]);
         $this->serv->send($fd, strval($key));
     } elseif ($_key[0] == 'CONFIG') {
         $key = $this->getConfig($_key[1], $_key[2]);
         $this->serv->send($fd, $key . self::EOF);
     } elseif ($_key[0] == 'REPORT') {
         $serverIp = $_key[1];
         $serviceName = $_key[2];
     } else {
         $this->serv->send($fd, "unkown" . self::EOF);
     }
 }
开发者ID:google2013,项目名称:StatsCenter,代码行数:22,代码来源:AopNetServer.php

示例7: OnTask

 public function OnTask(\swoole_server &$server, &$task_id, &$from_id, &$param)
 {
     /* @var $handler \DIServer\Handler */
     $handler = DIHandler($param['handlerID'])[$param['handlersKey']];
     if (!$handler) {
         DILog("Calling On not exist HandlerID " . $param['handlerID'] . ".");
         return;
     }
     $info = $server->connection_info($data['fd'], $from_id);
     $param['taskID'] = $task_id;
     $param['fromID'] = $from_id;
     $param['server'] =& $server;
     G('HandlerStart');
     $handler->__BeforeRun($param);
     $handler->Run($param);
     $handler->__AfterRun($param);
     G('HandlerEnd');
     $timeUsed = G('HandlerStart', 'HandlerEnd');
     if ($timeUsed >= C('HANDLER_SLOW_CHECK')) {
         $handler->SlowLog($param);
         //允许用户自定义慢处理参数日志
         DILog(get_class($handler) . " use " . $timeUsed . "s on task {$task_id}", 'w');
     }
 }
开发者ID:weijer,项目名称:DIServer,代码行数:24,代码来源:ReloadHelper.php

示例8: function

<?php

$serv = new swoole_server("::1", 9502, SWOOLE_PROCESS, SWOOLE_SOCK_UDP6);
$serv->set(array('worker_num' => 1));
$serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) {
    echo "[#" . posix_getpid() . "]\tClient[{$fd}]: {$data}\n";
    var_dump($serv->connection_info($fd, $from_id));
    $serv->send($fd, json_encode(array("hello" => '1213', "bat" => "ab")));
    //$serv->close($fd);
});
$serv->start();
开发者ID:liangkwok,项目名称:Swoole,代码行数:11,代码来源:udp_server.php

示例9: onPackage

 /**
  * @param $serv
  * @param $fd
  * @param $from_id
  * @param $data
  */
 function onPackage(\swoole_server $serv, $fd, $from_id, $data)
 {
     $conn = $serv->connection_info($fd, $from_id);
     /**
     *typedef struct
             {
             int32_t interface_id; //接口ID
             int32_t module_id; //模块ID
             int8_t success; //成功或失败
             int32_t ret_code; //返回码
             int32_t server_ip; //服务器端IP
             int32_t millisecond; //调用耗时单位毫秒
             int32_t time; //时间单位秒
             } module_stats;
     */
     $n = strlen($data) / self::STATS_PKG_LEN;
     if (is_float($n)) {
         $this->log("error udp pacakge size[" . strlen($data) . "]. data={$data}");
         return;
     }
     for ($i = 0; $i < $n; $i++) {
         $pkg_data = substr($data, $i * self::STATS_PKG_LEN, self::STATS_PKG_LEN);
         $this->parseStatsPackage($conn['remote_ip'], $pkg_data);
     }
 }
开发者ID:google2013,项目名称:StatsCenter,代码行数:31,代码来源:StatsServer.php

示例10: function

<?php

$serv = new swoole_server("::1", 9501, SWOOLE_PROCESS, SWOOLE_SOCK_TCP6);
$serv->set(array('worker_num' => 1));
$serv->on('connect', function ($serv, $fd, $from_id) {
    echo "[#" . posix_getpid() . "]\tClient@[{$fd}:{$from_id}]: Connect.\n";
});
$serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) {
    echo "[#" . posix_getpid() . "]\tClient[{$fd}]: {$data}\n";
    var_dump($serv->connection_info($fd));
    $serv->send($fd, json_encode(array("hello" => '1213', "bat" => "ab")));
    //$serv->close($fd);
});
$serv->on('close', function ($serv, $fd, $from_id) {
    echo "[#" . posix_getpid() . "]\tClient@[{$fd}:{$from_id}]: Close.\n";
});
$serv->start();
开发者ID:ppker,项目名称:swoole-src,代码行数:17,代码来源:tcp_server.php

示例11:

 function connection_info($fd)
 {
     return $this->sw->connection_info($fd);
 }
开发者ID:kilmas,项目名称:framework,代码行数:4,代码来源:Server.php

示例12: function

<?php 
$clientcount = 0;
$serv = new swoole_server("0.0.0.0", 10000);
echo "BenchServer v 0.1  By 709653949@qq.com admin at 10000  start ....\n";
$serv->set(array('worker_num' => 1, 'daemonize' => false));
$serv->on('connect', function ($serv, $fd) {
    global $clientcount;
    $fdinfo = $serv->connection_info($fd);
    $clientcount++;
    $clientinfo = "Client ip:" . $fdinfo["remote_ip"] . " port:" . $fdinfo["remote_port"] . " to fromport:" . $fdinfo["from_port"] . " Connected! count=" . $clientcount . "\n";
    echo $clientinfo;
});
$serv->on('receive', function ($serv, $fd, $from_id, $data) {
    $info = $serv->connection_info($fd, $from_id);
});
$serv->on('close', function ($serv, $fd) {
    global $clientcount;
    $fdinfo = $serv->connection_info($fd);
    $clientcount--;
    $clientinfo = "Client ip:" . $fdinfo["remote_ip"] . " port:" . $fdinfo["remote_port"] . " Closed.......\n";
    echo $clientinfo;
});
$serv->start();
开发者ID:xxoxx,项目名称:gitswoolestudy,代码行数:23,代码来源:BenchServer.php

示例13: onReceive

 /**
  * 对外提供接口
  *
  * @param  $server      swoole_server对象
  * @param $fd           TCP客户端连接的文件描述符
  * @param $from_id      TCP连接所在的Reactor线程ID
  * @param $data         收到的数据内容
  */
 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'] == '9504') {
         echo $data . PHP_EOL;
         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);
         //任务数据
         $list = $data['list'];
         //请求类型
         $type = $data['type'];
         switch ($type) {
             //添加定时器
             case 'add':
                 //添加定时器
                 $timeInterval = $list['s_interval'];
                 $taskId = $list['s_id'];
                 $timerId = $server->tick($timeInterval, array($this, 'onTimer'), $list);
                 //更新任务
                 Task::updateTimer($taskId, $timerId);
                 $data = array('code' => 200, 'msg' => '添加定时器成功', 'data' => null);
                 $server->send($fd, json_encode($data));
                 break;
                 //修改定时器
             //修改定时器
             case 'edit':
                 //修改url,定时器间隔时间
                 $data = array('code' => 200, 'msg' => '修改定时器成功', 'data' => null);
                 $server->send($fd, json_encode($data));
                 break;
                 //删除定时器
             //删除定时器
             case 'del':
                 echo '删除定时器: ' . date('Y-m-d H:i:s') . PHP_EOL;
                 //任务ID
                 $taskId = $list['s_id'];
                 //定时器ID
                 $timerId = $list['s_timerId'];
                 //删除定时器
                 swoole_timer_clear($timerId);
                 //删除任务
                 Task::delTask($taskId);
                 $data = array('code' => 200, 'msg' => '删除定时器成功', 'data' => null);
                 $server->send($fd, json_encode($data));
                 break;
             default:
                 $data = array('code' => 500, 'msg' => '非法请求', 'data' => null);
                 $server->send($fd, json_encode($data));
                 break;
         }
     }
 }
开发者ID:randy-ran,项目名称:scheduledTask,代码行数:81,代码来源:Timer.php

示例14: function

    //$serv->addtimer(1000);
});
$serv->on('workerStart', function ($serv, $worker_id) {
    echo "{$worker_id} start" . PHP_EOL;
    //if($worker_id == 0) $serv->addtimer(1000);
});
$serv->on('connect', function ($serv, $fd, $from_id) {
    //echo "[#".posix_getpid()."]\tClient@[$fd:$from_id]: Connect.\n";
    echo "{$fd} connect, worker:" . $serv->worker_id . PHP_EOL;
});
$serv->on('task', function ($serv, $task_id, $from_id, $data) {
});
$serv->on('finish', function ($serv, $fd, $from_id) {
});
$serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) {
    $conn = $serv->connection_info($fd);
    print_r($conn);
    echo "worker_id: " . $serv->worker_id . PHP_EOL;
    if (empty($conn['uid'])) {
        $uid = $fd + 1;
        if ($serv->bind($fd, $uid)) {
            $serv->send($fd, "bind {$uid} success");
        }
    } else {
        if (empty($serv->fdlist[$fd])) {
            $serv->fdlist[$fd] = $conn['uid'];
        }
        print_r($serv->fdlist);
        foreach ($serv->fdlist as $_fd => $uid) {
            $serv->send($_fd, "{$fd} say:" . $data . PHP_EOL);
        }
开发者ID:liangkwok,项目名称:Swoole,代码行数:31,代码来源:uid_dispatch.php

示例15: my_onReceive

function my_onReceive(swoole_server $serv, $fd, $from_id, $data)
{
    my_log("Worker#{$serv->worker_pid} Client[{$fd}@{$from_id}]: received: {$data}");
    $cmd = trim($data);
    if ($cmd == "reload") {
        $serv->reload();
    } elseif ($cmd == "task") {
        $task_id = $serv->task("task " . $fd);
        echo "Dispath AsyncTask: id={$task_id}\n";
    } elseif ($cmd == "taskclose") {
        $serv->task("close " . $fd);
        echo "close the connection in taskworker\n";
    } elseif ($cmd == "tasksend") {
        $serv->task("send " . $fd);
    } elseif ($cmd == "bigtask") {
        $serv->task(str_repeat('A', 8192 * 5));
    } elseif ($cmd == "taskwait") {
        $result = $serv->taskwait("taskwait");
        if ($result) {
            $serv->send($fd, "taskwaitok");
        }
        echo "SyncTask: result=" . var_export($result, true) . "\n";
    } elseif ($cmd == "taskWaitMulti") {
        $result = $serv->taskWaitMulti(array(str_repeat('A', 8192 * 5), str_repeat('B', 8192 * 6), str_repeat('C', 8192 * 8)));
        if ($result) {
            $resp = "taskWaitMulti ok\n";
            foreach ($result as $k => $v) {
                $resp .= "result[{$k}] length=" . strlen($v) . "\n";
            }
            $serv->send($fd, $resp);
        } else {
            $serv->send($fd, "taskWaitMulti error\n");
        }
    } elseif ($cmd == "hellotask") {
        $serv->task("hellotask");
    } elseif ($cmd == "taskcallback") {
        $serv->task("taskcallback", -1, function (swoole_server $serv, $task_id, $data) {
            echo "Task Callback: ";
            var_dump($task_id, $data);
        });
    } elseif ($cmd == "sendto") {
        $serv->sendto("127.0.0.1", 9999, "hello world");
    } elseif ($cmd == "close") {
        $serv->send($fd, "close connection\n");
        $result = $serv->close($fd);
    } elseif ($cmd == "info") {
        $info = $serv->connection_info(strval($fd), $from_id);
        var_dump($info["remote_ip"]);
        $serv->send($fd, 'Info: ' . var_export($info, true) . PHP_EOL);
    } elseif ($cmd == 'proxy') {
        $serv->send(1, "hello world\n");
    } elseif ($cmd == 'sleep') {
        sleep(10);
    } elseif ($cmd == 'foreach') {
        foreach ($serv->connections as $fd) {
            echo "conn : {$fd}\n";
        }
        return;
    } elseif ($cmd == 'tick') {
        $serv->tick(2000, function ($id) {
            echo "tick #{$id}\n";
        });
    } elseif ($cmd == 'addtimer') {
        $serv->addtimer(3000);
    } elseif ($cmd == "list") {
        $start_fd = 0;
        echo "broadcast\n";
        while (true) {
            $conn_list = $serv->connection_list($start_fd, 10);
            if (empty($conn_list)) {
                echo "iterates finished\n";
                break;
            }
            $start_fd = end($conn_list);
            var_dump($conn_list);
        }
    } elseif ($cmd == "list2") {
        foreach ($serv->connections as $con) {
            var_dump($serv->connection_info($con));
        }
    } elseif ($cmd == "stats") {
        $serv_stats = $serv->stats();
        $serv->send($fd, 'Stats: ' . var_export($serv_stats, true) . "\ncount=" . count($serv->connections) . PHP_EOL);
    } elseif ($cmd == "broadcast") {
        broadcast($serv, $fd, "hello from {$fd}\n");
    } elseif ($cmd == "error") {
        hello_no_exists();
    } elseif ($cmd == "exit") {
        exit("worker php exit.\n");
    } elseif ($cmd == 'pause') {
        echo "pause receive data. fd={$fd}\n";
        $serv->pause($fd);
    } elseif (substr($cmd, 0, 6) == "resume") {
        $resume_fd = substr($cmd, 7);
        $serv->resume($resume_fd);
    } elseif (substr($cmd, 0, 5) == "close") {
        $close_fd = substr($cmd, 6);
        $serv->close($close_fd);
    } elseif ($cmd == "shutdown") {
        $serv->shutdown();
//.........这里部分代码省略.........
开发者ID:google2013,项目名称:swoole-src,代码行数:101,代码来源:server.php


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