试用easyswoole 官网的爬虫项目时, 提示
PHP Fatal error: Uncaught SwooleCoroutineHttpClientException: you must configure with `enable-openssl` to support ssl connection in /Library/WebServer/Documents/es_spider/vendor/easyswoole/http-client/src/Handler/Swoole/Client.php:23
原因就是在编译swoole 扩展的时候没有设置支持openssl。 所以要重新编译swoole.so 。
- 下载swoole
下载地址, https://github.com/swoole/swoole-src/releases
下载的源码文件,放入 /usr/local/share/ 下。
tar -zvxf swoole-src-4.5.2.tar.gz
phpize
cd swoole-src-4.5.2
- 编译
- php-config文件
我的php 是通过brew install 安装, PHP的安装地址在 /usr/local/Cellar . 我使用的php 版本是 7.2 , 完整的地址为
/usr/local/Cellar/php@7.2/7.2.18/bin/php-config
- openssl 文件
/usr/local/Cellar/openssl@1.1/1.1.1g
- 开始编译
错误方式:./configure --with-php-config=/usr/local/Cellar/php@7.2/7.2.18/bin/php-config --enable-openssl
, 我没有指定 openssl 地址报错
正确方式./configure --with-php-config=/usr/local/Cellar/php@7.2/7.2.18/bin/php-config --with-openssl-dir=/usr/local/Cellar/openssl@1.1/1.1.1g --enable-sockets --enable-http2 --enable-mysqlnd
, 指定了openssl的文件夹就没有问题了。
- 生成swoole.so
make && make install
- 重启 apache
sudo apachectl restart
- 最终验证, 查看phpinfo
至此, easyswoole 官网的爬虫示例就可以跑起来了。
学到了继续分享继续关注你