Mac下swoole常见问题

Mac下安装swoole常见问题

一部分来自转载:三木的人生——3mu.me求知若饥,虚心若愚!

http://www.3mu.me/%E5%9C%A8-mac%E4%B8%8B%E5%AE%89%E8%A3%85-swoole-%E5%92%8C-swooledistributed-3-x-%E5%87%BA%E7%8E%B0%E7%9A%84%E9%97%AE%E9%A2%98%E6%95%B4%E7%90%86/

一部分来自,自己尝试解决

phpize运行报错

grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:

原因: 文件在这个目录下

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include

解决方案: 安装command line tool就自动配置好Unix开发环境 在命令行执行命令:xcode-select --install 参考资料: grep: /usr/include/php/main/php.h: No such file or directory(https://mengkang.net/755.html) macOS 中使用 phpize 动态添加 PHP 扩展的错误解决方法(https://www.cnblogs.com/imayanlong/p/6071805.html) mac 10.11 phpize 报错问题(https://segmentfault.com/q/1010000003882420)

编译Swoole报错:

swoole.h:414:10: fatal error: 'openssl/ssl.h' file not found
#include 

原因: openssl 未安装或 openssl 库不在标准位置中 解决方案:

1、确认是否安装了 openssl

brew search openssl 若未安装则执行命令brew install openssl进行安装

2、确认 openssl 库是否在标准位置中

ls /usr/local/include/openssl
No such file or directory

这就是问题所在了,找到 openssl/include/openssl 目录,并 cp 到 /usr/local/include 目录中。

ln -s /usr/local/Cellar/openssl/1.0.2o_1/include/openssl /usr/local/include/

一般情况下就可以解决该问题了。

但是,也可能会遇到很诡异的状况,上步没有解决问题,依然找不到 openssl/ssl.h 等文件 复制 openssl 源文件到 swoole 的源码目录中,编译就可以了。

cp -R  /usr/local/Cellar/openssl/1.0.2o_1/include/openssl swoole-src-2.1.3/include

这个肯定能解决问题了 参考资料: histMacOS 10.12.1 编译安装 Swoole 支持 openssl 模块错误处理(http://blog.163.com/liwei1987821@126/blog/static/1726649282017669619712/)

安装php72-redis扩展

➜  ~ brew search php72-redis
==> Searching local taps...
==> Searching taps on GitHub...
==> Searching blacklisted, migrated and deleted formulae...
No formula found for "php72-redis".
Closed pull requests:
Bump revision for php72-redis (https://github.com/Homebrew/homebrew-php/pull/4428)
php72-redis 3.1.2 (new formula) (https://github.com/Homebrew/homebrew-php/pull/4257)
enchant 2.2.0 (https://github.com/Homebrew/homebrew-core/pull/21807)
Add PHP 7.2.0-alpha.1 core formula (php72) (https://github.com/Homebrew/homebrew-php/pull/4211)
➜  ~ brew install php72-redis
Updating Homebrew...
==> Auto-updated Homebrew!

安装 hiredis 扩展

➜  ~ brew install hiredis
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (caskroom/cask).
No changes to formulae.

==> Downloading https://homebrew.bintray.com/bottles/hiredis-0.13.3.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring hiredis-0.13.3.high_sierra.bottle.tar.gz
/usr/local/Cellar/hiredis/0.13.3: 31 files, 189.4KB

安装 redis 和设置开机启动

brew install redis  
# 开机启动redis命令 
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents  

参考资料: 在mac上通过brew安装redis以及phpRedis扩展(https://blog.csdn.net/zrainload/article/details/78987352)

回退Mac上用Brew安装的PHP版本

brew list
brew unlink php56
brew link php55

参考资料: 回退Mac上用Brew安装的PHP版本(http://yansu.org/2014/09/26/use-old-version-of-brew-php.html)

支持http2报错

/private/tmp/pear/temp/swoole/php_swoole.h:148:2: error: "Enable http2 support, require nghttp2 library."

解决方案

brew install nghttp2

websocket服务开启后,服务连接没反应,只有退出时close回调才有反应

由于 websocket 是基于http_server做的,所以我将websocket同时也当做http_server使用
而我的websocket服务是集成在thinkPHP中的,
不知道为什么会接收websocket连接时没反应,
        $this->ws = new \Swoole\Http\Server(self::HOST, self::PORT);
        改为        $this->ws = new swoole_websocket_server(self::HOST, self::PORT);
就行了

这个也是Swoole-v4.2.3的问题, 新版本应该就好了

在listen多个端口时,进行多端口监听时报错,进程异常退出

[2018-10-30 00:58:25 $971.0]    WARNING swManager_check_exit_status: worker#2 abnormal exit, status=0, signal=11
A bug occurred in Swoole-v4.2.3, please report it.
The Swoole developers probably don't know about it,
and unless you report it, chances are it won't be fixed.
You can read How to report a bug doc before submitting any bug reports:
>> https://github.com/swoole/swoole-src/issues/2000
Please do not send bug reports in the mailing list or personal letters.
The issue page is also suitable to submit feature requests.

如果用的是Swoole-v4.2.3这个是由于版本问题,升到 swoole4.2.5之后就好了

转载于:https://my.oschina.net/chinaliuhan/blog/3063750

你可能感兴趣的:(Mac下swoole常见问题)