php sockets, swoole 扩展安装
swoole扩展依赖sockets扩展。
所以要先安装sockets扩展,sockets扩展在php源码包中存在。
所以要先下载对应版本的php源码
php源码ext目录
wget https://www.php.net/distributions/php-7.2.16.tar.gztar xvzf php-7.2.16.tar.gz -C .cd php-7.2.16cd /ext/sockets//Applications/XAMPP/bin/phpize./configure --enable-sockets --with-php-config=/Applications/XAMPP/bin/php-config-7.2.4makesudo make installsudo emacs /Applications/XAMPP/xamppfiles/etc/php.ini
如果下载速度慢,可以把链接粘贴到迅雷 https://www.php.net/distributions/php-7.3.27.tar.xz
在xshell用rz传到服务器
添加一行
extension="/Volumes/Applications/php/php-7.2.9/ext/sockets/modules/sockets.so"
安装完了之后
----------------------------------------------------------------------
Libraries have been installed in:/Volumes/Applications/php/php-7.2.9/ext/sockets/modulesIf you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:- add LIBDIR to the `DYLD_LIBRARY_PATH' environment variableduring executionSee any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
echo "export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Volumes/Applications/php/php-7.2.9/ext/sockets/modules" >> ~/.bash_profile
source !$
php -m | grep sockets
Warning: Module 'sockets' already loaded in Unknown on line 0
sockets
php.ini中不需要 extension="/Volumes/Applications/php/php-7.2.9/ext/sockets/modules/sockets.so" 这一行
$ sudo php -m | grep sockets
sockets
查看phpinfo
http://localhost/phpinfo.php
sockets
Sockets Support | enabled |
先找php-config
如果php安装到/usr/local/php路径下
find /usr/local/php/ -name "php-config*"
找到php-config在 /usr/local/php/bin/php-config
安装swoole
git clone https://gitee.com/swoole/swoole cd swoole/Applications/XAMPP/bin/phpize./configure --enable-openssl --enable-sockets --enable-mysqlnd --enable-http2 \--with-php-config=/Applications/XAMPP/bin/php-config-7.2.4make -j2sudo make install
开发环境可以不要open-ssl扩展 --enable-openssl 去掉
要安装的话参照这里: https://blog.csdn.net/fareast_mzh/article/details/100071833
Installing shared extensions: /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20170718/
Installing header files: /Applications/XAMPP/xamppfiles/include/php/
sudo emacs /Applications/XAMPP/xamppfiles/etc/php.ini
extension="swoole.so"
chenhuimingdeMacBook-Pro:swoole Mch$ php -m | grep swoole
swoole
测试swoole安装好了
<?php$http = new Swoole\Http\Server("0.0.0.0", 9501);$http->on("start", function($server) {echo "Swoole http server is started at http://0.0.0.1:9501\n";
});$http->on("request", function($request, $response) {$response->header("Content-Type", "text/html");$response->end("<p>Hello world!</p>");
});$http->start();
启动服务:
php http.php
Swoole http server is started at http://127.0.0.1:9501
$ curl -i http://192.168.1.102:9501
HTTP/1.1 200 OK
Content-Type: text/html
Server: swoole-http-server
Connection: keep-alive
Date: Sat, 10 Aug 2019 08:35:02 GMT
Content-Length: 19<p>Hello world!</p>
swoole官网 https://www.swoole.com/
swoole文档 https://wiki.swoole.com/#/
再试一个websocket的实例
websocket服务端:
<?php$server = new Swoole\Websocket\Server('0.0.0.0', 9503);$server->on('open', function($server, $req) {echo "connection open: {$req->fd}\n";
});$server->on('message', function($server, $frame) {echo "received message: {$frame->data}\n";$server->push($frame->fd, json_encode(['hello', 'world']));
});$server->on('close', function($server, $fd) {echo "connection close: {$fd}\n";
});$server->start();
浏览器端:
// ws, wss(web socket + ssl)
var connection = new WebSocket("ws://47.93.27.106:9503");connection.onopen = function(e) {console.log(e.currentTarget.url + " has opened.");connection.send('样本数据');
};connection.onmessage = function(e) {console.log("Received: " + e.data);
};
php sockets, swoole 扩展安装相关推荐
- PHP的swoole扩展安装方法详细教程
这篇文章主要为大家分享了PHP的swoole扩展安装方法详细教程,具有实用性和参考价值,感兴趣的小伙伴们可以参考一下 Swoole支持PHP 5.3.10以上版本,所以安装Swoole之前请先安装PH ...
- swoole php 使用教程,Swoole 扩展安装与使用入门
Swoole 扩展安装与使用入门 由 学院君 创建于2年前, 最后更新于 1年前 版本号 #3 37642 views 13 likes 5 collects Swoole 概述 Swoole 是面向 ...
- swoole扩展安装使用
前几天进行了swoole扩展的安装使用,这里记录一下遇到的坑和总结 我是在虚拟机里面先使用源码安装了一个php7.4的,然后根据swoole官方的安装命令 pecl install swoole . ...
- 编译安装 PHP 扩展 - 含 swoole 扩展安装和升级
编译安装 Redis 扩展 - phpredis 编译安装 Swoole 扩展 编译安装 Pcntl 扩展 编译安装 Sockets 扩展 编译安装 Event 扩展 编译安装 Mongodb 扩展 ...
- mac上brew安装swoole扩展,采坑之路
1.官网下载最新扩展 wget http://pear.php.net/go-pear.phar 说明:如果提醒你需要更新,则更新命令 2.开始安装 sudo pecl install swoole ...
- macos big sur安装php扩展_用PHP构建基于swoole扩展的socket服务(附PHP扩展安装步骤)...
最近公司的一项目中,需要用PHP搭建一个socket服务. 本来PHP是不适合做服务的,因为和第三方合作,需要采用高效而稳定的TCP协议进行数据通信.经过多次尝试,最终选择了开源的PHP扩展:swoo ...
- php7.1解压包安装,【Swoole】php7.1安装swoole扩展
参照:https://zixuephp.net/article-430.html 1.源码编译安装,PHP版本7.1.33 2.在已经编译好安装的php7.1中安装swoole扩展. 一.下载swoo ...
- php扩展swoole安装,php 安装swoole扩展
步骤 1.在swoole官网 https://www.swoole.com/ 下载需要安装的版本如通过git clone下载: git clone https://gitee.com/swoole/s ...
- PHP安装swoole扩展
个人服务器进行swoole安装 服务器 centos 6.8版本 PHP版本7.1.2 swoole手册建议PECL安装 pecl install swoole 执行这个命令之后发现没有pecl ...
最新文章
- 一个直接运行Windows命令行的软件
- python 内置方法的时间复杂度
- 使用自己的数据集训练GoogLenet InceptionNet V1 V2 V3模型(TensorFlow)
- 搞笑向, 面向IE8的webworker-ployfill
- OPPO或将于本月推出Find X2 英雄联盟 S10 限定版
- Windows Phone 7 使用Perst数据库的Demo——流水账
- k3金蝶 java版本_金蝶KIS旗舰版和K3wise的不同
- 【ROS】第一篇:ROS安装教程
- HBuilder X如何运行uni-app 项目
- 寻宝游戏设定_Excel寻宝游戏
- tinder和bumble_发布课程:Tinder,Reddit,Airbnb,Etsy和Uber如何吸引了第一批用户
- 移动机会网络中的节点分簇路由算法
- 央行:推动企业征信市场高质量发展
- Spanning-tree fast features配置案例
- 通过禁用文件夹权限解决微信pc端朋友圈自动播放视频的问题
- Java 操作 ElasticSearch
- 顺序表实现简单的【扑克牌】
- linux运维工程师2017,2017年Linux运维工程师经典面试题汇总
- ISTQB中的测试条件是什么?和测试用例的前置条件有什么区别?
- 2021互联网大厂端午礼盒大盘点~