常见错误
swoole 2018-05-12 18:34:51

1、websocket服务器收不到推送消息,本地调试正常

https://wiki.swoole.com/wiki/page/312.html

编译swoole扩展出现

fatal error: pcre.h: No such file or directory

原因是缺少pcre,需要安装libpcre:

 

ubuntu/debian:

C/C++ Code复制内容到剪贴板
  1. apt-get install libpcre3 libpcre3-dev  

 

centos/redhat:

C/C++ Code复制内容到剪贴板
  1. yum install pcre-devel  

 

其他Linux:
PCRE官方网站下载源码包,编译安装pcre库。

 

2、 swoole用协程mysql时报错:must be called in the coroutine

使用swoole开发项目,
有些地方遇到 must be called in the coroutine,
意思是需要在coroutine协程里运行。

swoole中的一些跟coroutine协程相关的接口,必须要在协程中执行,

比如

Coroutine\Channel

Coroutine\Redis

Coroutine\MySQL

解决的办法就是把相关代码放到协程里去。

举个例子:

PHP Code复制内容到剪贴板
  1. $db = new Swoole\Coroutine\MySQL();  

 

会提示
must be called in the coroutine

把代码放到协程中去就行了

PHP Code复制内容到剪贴板
  1. go(function() {  
  2.     $db = new Swoole\Coroutine\MySQL();  
  3. });  

 

 

 

本文来自于:http://www.yoyo88.cn/study/swoole/304.html

Powered by yoyo苏ICP备15045725号