快速安装和使用swoole的办法

方法一: 使用pecl 快速安装soole

如果特别慢,那么就需要设置代理


# 设置代理
pear config-set http_proxy http://127.0.0.1:8015


pecl channel-update https://pecl.php.net/channel.xml
# pecl install swoole 

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

参考文档

  1. 安装 Swoole
  2. download swoole source code
  3. php-fig
  4. swoole wiki
  5. github swoole source code
  6. 基础知识 php 四种设置回调函数的方式
  7. 依赖注入的方式
  8. 快速开始swoole
  9. php document
  10. swoole-cli
  11. swoole-clie download
  12. Swoole v5.0 版本新特性预览之新的运行模式
  13. swoole 使用例子
  14. Swoole-Cli 5.0.1 使用说明
  15. swoole运行流程图
  16. web搜索软件包或者应用程序的入口
  17. 使用最新版 gcc cmake msys2 Cygwin
  18. alpine、debian、ubuntu 常用的换源命令
  19. 构建PHP容器
  20. 构建php的两种模式(php-fpm和php-cli)的运行环境
  21. nginx容器与php-fpm容器连接方式
  22. 静态编译 PHP 8 系列、PHP7.4 、PHP7.3
  23. swoole 和 swow 是什么关系,有什么区别
  24. 静态编译PHP 运行时
  25. 构建PHP容器
posted @ 2022-11-02 04:12  jingjingxyk  阅读(456)  评论(0编辑  收藏  举报