方法一: 使用pecl 快速安装soole
如果特别慢,那么就需要设置代理
| |
| |
| pear config-set http_proxy http://127.0.0.1:8015 |
| |
| |
| pecl channel-update https://pecl.php.net/channel.xml |
| |
| |
| pear config-show |
| |
| |
| pecl install --configureoptions 'enable-sockets="yes" enable-openssl="yes" enable-mysqlnd="yes" enable-swoole-curl="yes" enable-cares="yes" enable-brotli="yes"' swoole |
| |
| |
| pear config-set http_proxy "" |
| |
方法二:swoole源码安装
swoole source code 源码一:
swoole source code 源码二:
| |
| git clone -b master --depth=1 --progress https://github.com/swoole/swoole-src.git |
| |
| cd swoole-src |
| phpize |
| ./configure --help |
| |
| ./configure --enable-sockets --enable-openssl --enable-brotli --enable-swoole-curl --enable-cares |
| |
| |
| make && sudo make install |
| |
| |
swoole-cli 特别赞
php 都不用安装了(直接内置 PHP runtime),可以直接像golang 或者nodejs 一样,下载下来,直接就能用
实际是把php完全静态编译了,摆脱动态依赖库
https://www.swoole.com/download
| |
| wget https://wenda-1252906962.file.myqcloud.com/dist/swoole-cli-with-loader-v5.0.1-dev-linux-x64.tar.xz |
| xz -d swoole-cli-with-loader-v5.0.1-dev-linux-x64.tar.xz |
| mkdir swoole-cli |
| mv swoole-cli-with-loader-v5.0.1-dev-linux-x64.tar swoole-cli |
| tar -xvf swoole-cli-with-loader-v5.0.1-dev-linux-x64.tar |
| ./swoole-cli --help |
| |
swoole 静态web服务
| <?php |
| |
| $http = new Swoole\Http\Server('127.0.0.1', 9501); |
| |
| $document_root = __DIR__; |
| |
| $http->set([ |
| 'document_root' => $document_root, |
| 'enable_static_handler' => true, |
| 'http_autoindex' => true, |
| 'http_index_files' => ['index.html', 'index.txt'], |
| ]); |
| |
| $http->on('start', function ($server) { |
| echo "Swoole http server is started at http://127.0.0.1:9501\n"; |
| }); |
| |
| $http->on('request', function ($request, $response) { |
| $response->header('Content-Type', 'text/plain'); |
| $response->end('Hello World'); |
| }); |
| |
| $http->start(); |
| |
运行
| swoole-cli web-server.php |
| |
| |
| # 照着例子就能用了 |
| |
| https://github.com/swoole/swoole-src/releases |
| https://pecl.php.net/package/swoole |
| https://gitee.com/swoole/swoole/tags |
| |
参考文档
- 安装 Swoole
- download swoole source code
- php-fig
- swoole wiki
- github swoole source code
- 基础知识 php 四种设置回调函数的方式
- 依赖注入的方式
- 快速开始swoole
- php document
- swoole-cli
- swoole-clie download
- Swoole v5.0 版本新特性预览之新的运行模式
- swoole 使用例子
- Swoole-Cli 5.0.1 使用说明
- swoole运行流程图
- web搜索软件包或者应用程序的入口
- 使用最新版 gcc cmake msys2 Cygwin
- alpine、debian、ubuntu 常用的换源命令
- 构建PHP容器
- 构建php的两种模式(php-fpm和php-cli)的运行环境
- nginx容器与php-fpm容器连接方式
- 静态编译 PHP 8 系列、PHP7.4 、PHP7.3
- swoole 和 swow 是什么关系,有什么区别
- 静态编译PHP 运行时
- 构建PHP容器
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具