swoole开启openssl

安装swoole扩展两种方式1. pecl 2. 编译安装

环境说明

  • 宿机win10
  • 操作主机vbox-ubuntu
  • 安装主机docker [letsdockerize/laradock-php-fpm:2.4-7.2]

pecl方式安装

pecl install swoole-4.4.4

执行上面命令后待定一段时间后、会出现下面询问对话输入[y]就是开启, 但是在dockerfile中无法自动为其输入[y]. 方法未找到. dockerfile可以使用编译方式安装.

...
381 source files, building
running: phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
enable sockets supports? [no] : 
enable openssl support? [no] : 
enable http2 support? [no] : 
enable mysqlnd support? [no] : 
building in /tmp/pear/temp/pear-build-defaultusernDqLij/swoole-4.4.1
....

编译安装

    curl -o /tmp/swoole.tar.gz https://github.com/swoole/swoole-src/archive/v4.4.1.tar.gz -L && \
    tar zxvf /tmp/swoole.tar.gz && cd swoole-src* && \
    phpize && \
    ./configure \
    --enable-openssl  \
    --enable-http2  \
    --enable-async-redis \
    --enable-mysqlnd && \
    make && make install && \
    docker-php-ext-enable swoole

查看swoole扩展信息

php –ri swoole

出现openssl字符说明已启用openssl

root@4c5bf38c1a5d:/var/www/html# php --ri swoole

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.4.1
Built => Sep  6 2019 05:54:34
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.1.0j  20 Nov 2018
http2 => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608

pecl install 参数选择 pecl help install

Options:
  -f, --force
        will overwrite newer installed packages
  -l, --loose
        do not check for recommended dependency version
  -n, --nodeps
        ignore dependencies, install anyway
  -r, --register-only
        do not install files, only register the package as installed
  -s, --soft
        soft install, fail silently, or upgrade if already installed
  -B, --nobuild
        don't build C extensions
  -Z, --nocompress
        request uncompressed files when downloading
  -R DIR, --installroot=DIR
        root directory used when installing files (ala PHP's INSTALL_ROOT), use packagingroot for RPM
  -P DIR, --packagingroot=DIR
        root directory used when packaging files, like RPM packaging
  --ignore-errors
        force install even if there were errors
  -a, --alldeps
        install all required and optional dependencies
  -o, --onlyreqdeps
        install all required dependencies
  -O, --offline
        do not attempt to download any urls or contact channels
  -p, --pretend
        Only list the packages that would be downloaded

相关资料

pecl-swoole
github-swoole-tag
pecl 安装swoole怎么开启openssl | 如果是 Nginx 代理到 Swoole,那么 Swoole 不需要配置 SSL 编译Swoole时指定–enable-openssl或–with-openssl-dir可以开启SSL

expect – 自动交互脚本 待研究

长连接使用前需解决的问题

长连接、swoole、easyswoole

  • 部署安装
  • websocket、socket、mqtt服务部署及联调
  • 不同协议中的交互 硬件使用mqtt、APP使用socket
  • 每次传输的数据如何转入到对应的逻辑方法处理(http中每个URL可以对应到指定的方法)
  • 传输数据可用的数据类型有几种(二进制、json)
  • 连接认证、数据加密
  • 多进程、多线程、协程
  • 分布式部署

easyswoole

官方安装文档

安装部分

本次使用的docker安装部署、官方已给出dockerfile、但注释了 Install easyswoole下面的三行、在build的时候先不安装

build好后启动并进入镜像安装easyswoole. composer require easyswoole/easyswoole=3.x-dev

{
    # composer require  的时候不会出现下面autoload部分需要自己添加后执行 composer dumpautoload 更新命名空间映射
    "autoload": {
        "psr-4": {
            "App\\": "App/"
        }
    },
    "require": {
        "easyswoole/easyswoole": "3.x-dev"
    }
}

如果出现下面代码、并检查路径及文件名都正确的话在检查composer.json中autoload空间映射是否正确.

[Uncaught Error: Class 'App\WebSocket\WebSocketParser' not found in /var/www/code/EasySwooleEvent.php:37

websocket服务调试

websocket部署测试-官方例子

服务端使用官方文档例子, websocket客户端使用 在线调试

{"action":"hello","content":"easyswoole"} 发送的json字符串, 如果json字符不规范可以f12打开Console然后使用JSON.stringify({action: 'hello', content: 'easyswoole'})

手动部署

swoole 部署错误

需手动安装包: composer require easyswoole/socket