swoole
李景山-编程者
就是想简单的写代码.......................
展开
-
[李景山php]Swoole 编写 IM通信
Swoole 编写 IM通信服务器端口://创建websocket服务器对象,监听0.0.0.0:9502端口$ws = new swoole_websocket_server("0.0.0.0", 9502);//监听WebSocket连接打开事件$ws->on('open', function ($ws, $request) {$GLOBALS['fd'][$request->fd]['原创 2017-05-02 16:54:25 · 1498 阅读 · 0 评论 -
[李景山php] swoole 事件添加
$fp = stream_socket_client("tcp://www.qq.com:80", $errno, $errstr, 30);fwrite($fp,"GET / HTTP/1.1\r\nHost: www.qq.com\r\n\r\n");swoole_event_add($fp, function($fp) { $resp = fread($fp, 8192);原创 2017-05-17 09:23:17 · 263 阅读 · 0 评论 -
[李景山php] swoole 异步 文件写入
$file_content = 'jingshan';swoole_async_writefile('test.log', $file_content, function($filename) { echo "wirte ok.\n";}, $flags = 0);原创 2017-05-17 09:22:36 · 875 阅读 · 2 评论 -
[李景山php] swoole 异步文件读取
swoole_async_readfile(__DIR__."/server.php", function($filename, $content) { echo "$filename: $content";});原创 2017-05-17 09:21:53 · 309 阅读 · 0 评论 -
[李景山php] swoole dns 查询
swoole_async_dns_lookup("www.baidu.com", function($host, $ip){ echo "{$host} : {$ip}\n";});原创 2017-05-17 09:20:47 · 269 阅读 · 0 评论 -
[李景山php] swoole 锁机制
$lock = new swoole_lock(SWOOLE_MUTEX);echo "[主进程]创建锁\n";$lock->lock();if (pcntl_fork() > 0){ sleep(1); $lock->unlock();}else{ echo "[子进程]等待锁\n"; $lock->lock(); echo "[子进程]获取锁\n"原创 2017-05-17 09:20:08 · 740 阅读 · 0 评论 -
[李景山php] swoole 之web服务器
$http = new swoole_http_server("0.0.0.0", 9501);$http->on('request', function ($request, $response) { var_dump($request->get, $request->post); $response->header("Content-Type", "text/html; cha原创 2017-05-16 17:39:53 · 474 阅读 · 0 评论 -
[李景山php] swoole之 UDP服务器实现
$serv = new swoole_server("127.0.0.1", 9502, SWOOLE_PROCESS, SWOOLE_SOCK_UDP);//监听数据接收事件$serv->on('Packet', function ($serv, $data, $clientInfo) { $serv->sendto($clientInfo['address'], $clientInf原创 2017-05-16 17:38:52 · 999 阅读 · 0 评论 -
[李景山php] swoole系列实用案例-TCPserver
//创建Server对象,监听 127.0.0.1:9501端口$serv = new swoole_server("127.0.0.1", 9501);//监听连接进入事件$serv->on('connect', function ($serv, $fd) { echo "Client: Connect.\n";});//监听数据接收事件$serv->on('receive',原创 2017-05-16 17:37:44 · 423 阅读 · 0 评论 -
为什么需要通信协议
TCP协议在底层机制上解决了UDP协议的顺序和丢包重传问题。但相比UDP又带来了新的问题,TCP协议是流式的,数据包没有边界。应用程序使用TCP通信就会面临这些难题。因为TCP通信是流式的,在接收1个大数据包时,可能会被拆分成多个数据包发送。多次Send底层也可能会合并成一次进行发送。这里就需要2个操作来解决:分包:Server收到了多个数据包,需要拆分数据包 合包:Server收到的数据只是包的原创 2017-04-21 15:44:33 · 2023 阅读 · 0 评论 -
ubuntu16.04 swoole 安装
编译安装: 1 下载源文件 下载地址:https://git.oschina.net/swoole/swoole/tree/v2.0.5 2 上传解压缩 unzip 解压基础环境 3 安装基础环境 apt-get install nginx php php-dev mysql-server -y 4 安装扩展swoole扩展库 apt-get install nghttp2 5 进原创 2017-04-21 15:07:06 · 5939 阅读 · 0 评论 -
swoole 安装
1 下载源文件 下载地址:https://git.oschina.net/swoole/swoole/tree/v2.0.5 2 上传解压缩 unzip 解压基础环境 3 安装基础环境 apt-get install nginx php php-dev mysql-server -y 4 进行扩展安装原创 2017-04-21 11:44:39 · 613 阅读 · 0 评论 -
[李景山php] swoole 异步 mysql 连接
$db = new swoole_mysql;$server = array( 'host' => '192.168.50.145', 'user' => 'root', 'password' => 'flzx_3QC', 'database' => 'mysql', 'chatset' => 'utf8', //指定字符集);$db->connect($原创 2017-05-17 09:24:17 · 1375 阅读 · 0 评论