× 警告!旧版文档已经暂停维护,请查看新版文档。点击前往新版文档

非协程特性独立扩展 (swoole_async)

4.3版本开始我们逐渐开始移除与协程无关的模块,包括异步客户端、消息队列等。

考虑到Swoole-1.x版本目前依然有大量用户使用,因此移除模块会转到另外一个混杂扩展(swoole_async)中进行维护。

模块列表

  • 异步文件IO,如swoole_async_read
  • 异步Http/WebSocket客户端
  • 异步Redis客户端
  • 异步MySQL客户端
  • swoole_msgqueue
  • swoole_memory_pool
  • swoole_ringqueue
  • swoole_mmap
  • swoole_channel

扩展编译

git clone https://github.com/swoole/async-ext.git
cd async-src
phpize
./confiugre
make -j 4
sudo make install
  • 编译将生成swoole_async.so新扩展
  • 此扩展依赖swoole.so扩展,必须先加载swoole.so再加载swoole_async.so

配置文件

修改php.ini加载扩展。

extension=swoole.so
extension=swoole_async.so

可以通过php -m看到swooleswoole_async两个扩展。


  • 斯内克

    make的时候 有6个error /home/wangzilong/async-ext/swoole_async.cc:186:25: error: ‘swoole_async’ was not declared in this scope SW_INIT_CLASS_ENTRY(swoole_async, "Swoole\Async", "swoole_async", NULL, swoole_async_methods); ^ /home/wangzilong/async-ext/swoole_async.cc:186:98: error: ‘SW_INIT_CLASS_ENTRY’ was not declared in this scope SW_INIT_CLASS_ENTRY(swoole_async, "Swoole\Async", "swoole_async", NULL, swoole_async_methods); ^ /home/wangzilong/async-ext/swoole_async.cc:187:99: error: ‘SW_SET_CLASS_SERIALIZABLE’ was not declared in this scope SW_SET_CLASS_SERIALIZABLE(swoole_async, zend_class_serialize_deny, zend_class_unserialize_deny); ^ /home/wangzilong/async-ext/swoole_async.cc:188:63: error: ‘SW_SET_CLASS_CLONEABLE’ was not declared in this scope SW_SET_CLASS_CLONEABLE(swoole_async, zend_class_clone_deny); ^ /home/wangzilong/async-ext/swoole_async.cc:189:85: error: ‘SW_SET_CLASS_UNSET_PROPERTY_HANDLER’ was not declared in this scope SW_SET_CLASS_UNSET_PROPERTY_HANDLER(swoole_async, zend_class_unset_property_deny);

    看不懂啊

  • 斯内克

    make的时候 有6个error /home/wangzilong/async-ext/swoole_async.cc:186:25: error: ‘swoole_async’ was not declared in this scope SW_INIT_CLASS_ENTRY(swoole_async, "Swoole\Async", "swoole_async", NULL, swoole_async_methods); ^ /home/wangzilong/async-ext/swoole_async.cc:186:98: error: ‘SW_INIT_CLASS_ENTRY’ was not declared in this scope SW_INIT_CLASS_ENTRY(swoole_async, "Swoole\Async", "swoole_async", NULL, swoole_async_methods); ^ /home/wangzilong/async-ext/swoole_async.cc:187:99: error: ‘SW_SET_CLASS_SERIALIZABLE’ was not declared in this scope SW_SET_CLASS_SERIALIZABLE(swoole_async, zend_class_serialize_deny, zend_class_unserialize_deny); ^ /home/wangzilong/async-ext/swoole_async.cc:188:63: error: ‘SW_SET_CLASS_CLONEABLE’ was not declared in this scope SW_SET_CLASS_CLONEABLE(swoole_async, zend_class_clone_deny); ^ /home/wangzilong/async-ext/swoole_async.cc:189:85: error: ‘SW_SET_CLASS_UNSET_PROPERTY_HANDLER’ was not declared in this scope SW_SET_CLASS_UNSET_PROPERTY_HANDLER(swoole_async, zend_class_unset_property_deny);

    看不懂啊

  • 丶蓬蒿人

    我去 一堆error 一堆warning 还是用4.2吧

  • 逝水无痕

    64位这样编译 CFLAGS="-O3 -fPIC" ./configure

  • hmk

    这个扩展真的有问题啊,无法安装

  • ecareyu

    怎么装啊?我用的是homestead,但是安装时候报了 fatal error: ext/swoole/php_swoole.h,但是我swoole用的是pecl装到,这两个扩展编译的时候还是依赖的啊?怎么解决,有哪位大佬指点下呗?

  • qinaction110

    ./php_swoole_async.h:26:10: fatal error: 'ext/swoole/php_swoole.h' file not found

    include "ext/swoole/php_swoole.h"

    同样的错误,大家都解决没

  • BathSmelting

    安装提示缺少【ext/swoole/config.h 】这个文件

  • BathSmelting

    安装提示缺少【ext/swoole/ 】这个目录,如果引入swoole的目录则php_swoole.h 会报缺少【swoole.h|server.h|client.h|async.h】等文件,再引入之后,报的错就看不懂了

  • 最美的太洋

    大家有没有解决这个扩展问题

  • 简单不简单

    这个扩展报了我100行错误提示

  • 简单不简单

    这个问题我找了三天终于知道为什么了 是因为官方给的扩展和你swoole的版本不一致造成的 https://github.com/swoole/ext-async/releases 用这个链接,找到与你swoole版本一致的扩展就可以完美解决! 谁在交流群,添加了没反应,麻烦把我拉进去下 963877200 谢谢!

  • z
    z

    出现变量未声明的错误: /home/ext-async/swoole_async.cc: 在函数‘int zm_startup_swoole_async(int, int)’中: /home/ext-async/swoole_async.cc:1708:44: 错误:‘swoole_version_id’在此作用域中尚未声明 if (PHP_SWOOLE_EXT_ASYNC_VERSION_ID != swoole_version_id()) ^~~~~~~~~~~~~~~~~ /home/ext-async/swoole_async.cc:1708:44: 附注:suggested alternative: ‘swoole_redis_init’ if (PHP_SWOOLE_EXT_ASYNC_VERSION_ID != swoole_version_id()) ^~~~~~~~~~~~~~~~~ swoole_redis_init make: *** [Makefile:193:swoole_async.lo] 错误 1

  • 豆泥豆泥

    ./php_swoole_async.h:26:10: fatal error: 'ext/swoole/php_swoole.h' file not found

    include "ext/swoole/php_swoole.h"

         ^~~~~~~~~~~~~~~~~~~~~~~~~
    

    In file included from /usr/local/Cellar/ext-async/swoole_channel.c:19: ./php_swoole_async.h:26:10: fatal error: In file included from 'ext/swoole/php_swoole.h' file not found /usr/local/Cellar/ext-async/swoole_async.cc:17: ./php_swoole_async.h:26:10: fatal error: 'ext/swoole/php_swoole.h' file not found

    include "ext/swoole/php_swoole.h"#include "ext/swoole/php_swoole.h"

    总是编译失败是什么原因?

  • 豆泥豆泥

    ./php_swoole_async.h:26:10: fatal error: 'ext/swoole/php_swoole.h' file not found

    include "ext/swoole/php_swoole.h"

         ^~~~~~~~~~~~~~~~~~~~~~~~~
    

    In file included from /usr/local/Cellar/ext-async/swoole_channel.c:19: ./php_swoole_async.h:26:10: fatal error: In file included from 'ext/swoole/php_swoole.h' file not found /usr/local/Cellar/ext-async/swoole_async.cc:17: ./php_swoole_async.h:26:10: fatal error: 'ext/swoole/php_swoole.h' file not found

    include "ext/swoole/php_swoole.h"#include "ext/swoole/php_swoole.h"

    这是什么问题呀