编译安装 [编辑本页]

Swoole扩展是按照php标准扩展构建的。使用phpize来生成php编译配置,./configure来做编译配置检测,make进行编译,make install进行安装。

  • 请下载releases版本的swoole,直接从github主干上拉取最新代码可能会编译不过
  • 如果当前用户不是root,可能没有php目录的写权限,安装时需要sudo或者su
  • 如果是在git分支上直接git pull更新代码,重新编译前务必要执行make clean

安装准备

安装swoole前必须保证系统已经安装了下列软件

php-5.3.10 或更高版本
gcc-4.4 或更高版本
make
autoconf
pcre (centos系统可以执行命令:yum install pcre-devel)

下载地址

下载源代码包后,在终端进入源码目录,执行下面的命令进行编译和安装

cd swoole
phpize
./configure
make 
sudo make install

PECL

swoole项目已收录到PHP官方扩展库,除了手工下载编译外,还可以通过PHP官方提供的pecl命令,一键下载安装swoole

pecl install swoole

配置php.ini

编译安装成功后,修改php.ini加入

extension=swoole.so

通过php -mphpinfo()来查看是否成功加载了swoole,如果没有可能是php.ini的路径不对,可以使用php -i |grep php.ini来定位到php.ini的绝对路径。


  • 王尧

    /root/test/swoole-swoole-1.6.11-stable/src/pipe/PipeEventfd.c: In function ‘swPipeEventfd_create’: /root/test/swoole-swoole-1.6.11-stable/src/pipe/PipeEventfd.c:47: error: ‘EFD_SEMAPHORE’ undeclared (first use in this function) /root/test/swoole-swoole-1.6.11-stable/src/pipe/PipeEventfd.c:47: error: (Each undeclared identifier is reported only once /root/test/swoole-swoole-1.6.11-stable/src/pipe/PipeEventfd.c:47: error: for each function it appears in.) make: *** [src/pipe/PipeEventfd.lo] Error 1 报这个错怎么解决

  • 小草

    [root@cloud examples]# php server.php PHP Fatal error: swoole_server_on: unkown handler[ManagerStart]. in /usr/local/swoole-master/examples/server.php on line 151

    我安装完swoole 运行php examples/server.php 他出现上面的错误

  • zhouleyu

    /root/test/swoole-swoole-1.6.11-stable/src/pipe/PipeEventfd.c:

  • 李逍遥

    没有安装说明啊。或者安装指导。

  • changlong.xu

    swoole-swoole-1.7.2-stable php -m|grep swo

    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/swoole.so' - /usr/lib64/php/modules/swoole.so: undefined symbol: mkostemp in Unknown on line 0

  • 天南

    centos 编译发生错误:libtool: link: `swoole_lock.lo' is not a valid libtool object

  • 天南

    本机libtool版本 2.4.2

  • yeswan

    PHP Fatal error: Class 'swoole_server' not found in /opt/lampp/wwwroot/server.php on line 2

    linux this error

  • 陈旭镛

    缺少mysql头文件

    php_mysqli_structs.h:64:23: fatal error: my_global.h: No such file or directory 没有找到mysqlclient的头文件,需要安装mysqlclient-dev

    编译源码安装mysql时候,实际上应该是: ./configure --with-php-config=/www/php-5.5.15/bin/php-config --enable-sockets --enable-async-mysql=/www/mysql

    --enable-async-mysql 需要指定路径

  • Kev

    怎么没有windows下的dll 搞歧视是么

  • 陈春瑜666

    编译成功,make时报错: /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c:2243: error: too many arguments to function ‘zend_exception_error’ /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c: In function ‘php_swoole_onMasterClose’: /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c:2280: error: too many arguments to function ‘zend_exception_error’ /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c: In function ‘zif_swoole_server_start’: /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c:2326: warning: dereferencing type-punned pointer will break strict-aliasing rules /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c: In function ‘zif_swoole_server_send’: /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c:2453: warning: dereferencing type-punned pointer will break strict-aliasing rules /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c: In function ‘zif_swoole_server_sendfile’: /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c:2549: warning: dereferencing type-punned pointer will break strict-aliasing rules /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c: In function ‘zif_swoole_server_addlisten’: /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c:2590: warning: dereferencing type-punned pointer will break strict-aliasing rules /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c: In function ‘zif_swoole_server_deltimer’: /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c:2614: warning: dereferencing type-punned pointer will break strict-aliasing rules /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c: In function ‘zif_swoole_server_addtimer’: /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c:2636: warning: dereferencing type-punned pointer will break strict-aliasing rules /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c: In function ‘zif_swoole_server_taskwait’: /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c:2849: warning: dereferencing type-punned pointer will break strict-aliasing rules /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c: In function ‘zif_swoole_server_task’: /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c:2954: warning: dereferencing type-punned pointer will break strict-aliasing rules /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c: In function ‘zif_swoole_server_finish’: /data1/www/htdocs/ccy/software/swoole-src-swoole-1.7.4-stable/swoole.c:3021: warning: dereferencing type-punned pointer will break strict-aliasing rules make: *** [swoole.lo] Error 1

    哪位遇到此问题并成功解决的?是否与G++有关?

  • 薛原

    /home/poke/swoole-1.7.2/swoole.c:1948: error: too many arguments to function 'zend_exception_error' 编译报错怎么破?

  • Rango-韩天峰

    你是用Linux发行版自带的PHP么,建议自己编译一个PHP版本。

  • Pader

    建议搞一个 Windows 版的,不一定真要实现高性能,就像 Nginx Redis 那样的,至少在 Windows 下可以调试开发。。

  • 夜幕林

    建议对于编译时使用了--enable-swoole-debug,在初始化服务的时候可以set 是否debug。不然有时候开发的时候,打印的数据都太多。

  • 心的二分之1

    load swoole.so,重启lnmp的时候 报错了 PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/swoole.so 话说编译完成后,.so文件的位置是什么呢

  • 卢驰

    ./configure command not found 这个是什么原因

  • 李珍珍

    为什么 没有 config.w32 php_*.def 等文件、、、、

  • 田雨

    php5.6,已经启用了sockets ./configure --enable-sockets --with-php-config=/usr/local/php6/bin/php-config --enable-swoole-debug -enable-async-mysql --enable-ringbuffer make的时候就会出现 Enable sockets support, But no sockets extension

  • 瞿瞿Green_yy

    谢谢提醒,不过应该是源码编译swoole的时候,不是mysql

  • 阮刚

    添加-enable-swoole-debug编译选项后报错,如下: /root/swoole-src-master/src/factory/FactoryProcess.c: 在函数‘swFactoryProcess_finish’中: /root/swoole-src-master/src/factory/FactoryProcess.c:764: 错误:‘sdata’未声明(在此函数内第一次使用) /root/swoole-src-master/src/factory/FactoryProcess.c:764: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其 /root/swoole-src-master/src/factory/FactoryProcess.c:764: 错误:所在的函数内也只报告一次。) make: *** [src/factory/FactoryProcess.lo] 错误 1

  • 阮刚

    还有,使用--enable-async-mysql=/usr/local/mysql参数,貌似没有编译进去。跑async_mysql2.php脚本还是提示找不到swoole_get_mysqli_sock函数

  • neil

    我也遇到这个问题了,请问如何解决?

  • 沈新波

    Enable async_mysql support, But no mysqli or mysqlnd.怎么解决?

  • 谁伴我闯荡

    真不明白为何非要搞Windows的,搞个SAMBA协议,装个Linux虚拟机,共享下开发目录,一样的本地调试!

  • 李想best

    不错,你说的是正确的

  • 李想best

    可能是找不到mysql相关的库文件,我编译时刚开始报错,后来--enable-async-mysql=/usr/include/mysql就可以了,环境是CentOS6.4 mysql是yum安装的!

  • 倪鹤翔

    Zend Guard Loader requires Zend Engine API version 220090626. The Zend Engine API version 220121212 which is installed, is newer. Contact Zend Technologies at http://www.zend.com/ for a later version of Zend Guard Loader.

  • lengchun

    [root@lengchun swoole-src-swoole-1.7.16-stable]# LDFLAGS="-L/opt/mysql/lib" CPPFLAGS="-I/opt/mysql/include" ./configure --with-php-config=/opt/php54/bin/php-config --enable-async-mysql=/opt/mysql/include --enable-swoole --with-swoole --enable-openssl --enable-ringbuffer --enable-sockets=/opt/php54/include/php/ext/sockets --enable-swoole-debug

  • Allan

    git主干会出现问题,用release的编译通过

  • Jerry_泽键

    指定路径后是能正常编译了,但是实际上enable-async-mysql选项失效了,异步的mysql方法没有编进去,不是这样的吗?

  • Qesy

    [呵呵][呵呵][呵呵][呵呵][呵呵][呵呵][呵呵]

  • 好东西啊

    好东西啊

  • 曹

    需要gcc4.4版本及以上

  • redfox241

    error: too many arguments to function ‘zend_exception_error’ 编译报错,你们怎么解决的?

  • 陈江飞

    hecking for ext/mysqli support... PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/swoole.so'

  • shuqi888

    FreeBSD 10.2 x64版本,PHP 5.6环境下用从官网下载的源码解压安装失败,后来通过/usr/ports/devel/pecl-swoole目录make install成功

  • 微内推

    Fatal error: Call to undefined function swoole_get_mysqli_sock() ;Who can tell me why?

  • bjlzt

    [花心]

  • 石长春

    要停止正在运行的swoole服务

  • 米天大汤

    php7 php5.5两个版本共存,分别安装swoole,现在php5.5的成功,7的extensions目录下也有swoole.so,php.ini也添加了extension=swoole.so,重启了php7-fpm,php -m还是没有,swoole 1.8.4 , pecl方式也安装了,想过一样。[衰]

  • 米天大汤

    在常见错误里面找到原因和解决方案了。多谢

  • 楚-白七

    PHP Fatal error: Can't inherit abstract function Swoole\Server\Driver::run() (previously declared abstract in Swoole\Server\Base) in /home/ftp/1520/im_webin/im_webin/webim/vendor/matyhtf/swoole_framework/libs/Swoole/Server/Base.php on line 7

  • 郝多

    cygwin下编译swoole 1.8.4-stable,居然缺少pcre.h文件: make报错: /cygdrive/c/Users/modian/Downloads/swoole-src-swoole-1.8.4-stable/swoole-src-swoole-1.8.4-stable/include/swoole.h: 在函数‘swoole_strtolower’中: /cygdrive/c/Users/modian/Downloads/swoole-src-swoole-1.8.4-stable/swoole-src-swoole-1.8.4-stable/include/swoole.h:1034:9: 警告:数组下标类型为‘char’ [-Wchar-subscripts] c = tolower(c); ^ In file included from /usr/include/php/ext/spl/spl_iterators.h:27:0, from /cygdrive/c/Users/modian/Downloads/swoole-src-swoole-1.8.4-stable/swoole-src-swoole-1.8.4-stable/swoole.c:28: /usr/include/php/ext/pcre/php_pcre.h: 在文件作用域: /usr/include/php/ext/pcre/php_pcre.h:29:18: 致命错误:pcre.h:No such file or directory #include "pcre.h" ^ 编译中断。 Makefile:180: recipe for target 'swoole.lo' failed make: *** [swoole.lo] Error 1

  • 郝多

    pecl install swoole 同样的错误。。 cygwin安装pcre包后,继续编译遇到新错误: /src/core/base.c:23:22: 致命错误:execinfo.h:No such file or directory

    查了一下,execinfo.h是GNU的文件,windows下没此文件,只好给cygwin安装GNU开发包。。。

  • 郝多

    由于兼容问题,gunlib不针对cygwin提供execinfo.h ,这是gnu官方文档:https://www.gnu.org/software/gnulib/manual/html_node/execinfo_002eh.html : This header file is missing on some platforms: Mac OS X 10.3, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin, mingw, MSVC 9, Interix 3.5, BeOS. 【结论,cygwin下无法继续make下去】

  • 郝多

    最新: swoole-src-swoole-1.8.5-beta 版本下,cygwin可以完成make:

    libtool: install: cp ./.libs/swoole.lai /cygdrive/c/Users/modian/Downloads/swoole-src-swoole-1.8.5-beta/swoole-src-swoole-1.8.5-beta/modules/swoole.la

    Build complete. Don't forget to run 'make test'

  • 朱荣

    今天刚好解决 在centos 编译swoole 1.8.4 --enable-async-mysql 具体步骤是 yum install mysql mysql-devel ,不是前面提到的 安装mysqlclient ./configure --enable-async-mysql=/usr/include/mysql

  • jepson

    你好 我发现 1.5版本之后 configure都没有 使用--enable-async-mysql这个参数了

  • ming

    服务器没有联网,不能使用pecl upgrade swoole在线更新。请问1.8.5stable怎么通过源码编译方式升级到1.8.8stable?

  • ming

    刚才直接下载了1.8.8-stable,tar.gz,解压后通过phpize方式,安装的1.8.8,重启了php-fpm,kill掉了原来的swoole server后还是原来的版本号1.8.5,请问是哪一步没有做造成的?

  • ming

    已经OK,重新编译安装后会生成新的swoole.so文件,直接将该文件覆盖之前的swoole.so文件即可。

  • 昌维

    我也是这样 我是ubuntu14 64bit,检查了其他组件版本都没问题

  • 王南

    I have read, thank you!

  • Rango-韩天峰

    已经改为内置了,不需要这个编译参数。

  • allen

    centos PHP7 ,环境已安装成功。测试通过。总体来说,安装比较简单。[嘻嘻]

  • 彭涛

    安装完后,php -m没有swoole啊,用了两种方法安装都没有,修改php.in也是没用

  • 李军锋

    php server.php 这个事系统自带的php /Applications/XAMPP/bin/php server.php server.php 这个php有swoole扩展的

  • 休闲时间

    今天部署PHP多版本共存,遇到些问题,在编译安装swoole时,./configure需要一些参数,完整如下: ./configure --with-php-config=/usr/local/php7/bin/php-config 后边路径请替换成自己的实际路径

  • huanganxin

    debian:~/phpcode$ php -f d.php [Thu Jan 12 22:44:34 2017] Script: '/home/eric/phpcode/d.php' /home/eric/software/php-7.1.0/Zend/zend_string.h(122) : Freeing 0xb6a011b8 (20 bytes), script=/home/eric/phpcode/d.php Last leak repeated 7 times [Thu Jan 12 22:44:34 2017] Script: '/home/eric/phpcode/d.php' /home/eric/software/swoole/php7_wrapper.h(310) : Freeing 0xb6a012f8 (16 bytes), script=/home/eric/phpcode/d.php [Thu Jan 12 22:44:34 2017] Script: '/home/eric/phpcode/d.php' /home/eric/software/php-7.1.0/Zend/zend_API.c(1060) : Freeing 0xb6a57280 (44 bytes), script=/home/eric/phpcode/d.php [Thu Jan 12 22:44:34 2017] Script: '/home/eric/phpcode/d.php' /home/eric/software/php-7.1.0/Zend/zend_closures.c(463) : Freeing 0xb6a5c460 (192 bytes), script=/home/eric/phpcode/d.php [Thu Jan 12 22:44:34 2017] Script: '/home/eric/phpcode/d.php' /home/eric/software/php-7.1.0/Zend/zend_hash.c(138) : Freeing 0xb6a5e500 (224 bytes), script=/home/eric/phpcode/d.php === Total 12 memory leaks detected ===

    php版本:7.1 swoole版本:2.0.5

    d.php 内容: <?php $db = new Swoole\MySQL; $server = array( 'host' => 'localhost', 'user' => 'root', 'password' => '', 'database' => 'kfb_a', );

    $db->connect($server, function ($db, $result) { $db->query("show tables", function (Swoole\MySQL $db, $result) { if ($result === false) { var_dump($db->error, $db->errno); } elseif ($result === true) { var_dump($db->affected_rows, $db->insert_id); } else { var_dump($result); $db->close(); } }); });

  • Lenix

    cd swoole phpize ./configure --enable-sockets=/usr/include/php/20151012/ext/sockets
    make sudo make install

  • 瀚海

    完全同样的错误 我的解决方式是把make & make install 分开 就不再报错了

  • 宁静致远

    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/swoole.so' - /usr/lib64/php/modules/swoole.so: undefined symbol: COROG in Unknown on line 0

  • 宁静致远

    安装成功,加载不成功

  • PSB

    文档中的 php -m 能看到swoole 但是在phpinfo()探针函数中看不到swoole扩展模块

  • gglinux/db

    PHP下面的安装,大家可以参考下:http://gglinux.com/2017/04/01/php7_install/

  • QQ

    没有安装指导!没有window版本!差评

  • 夏至冰当融

    phpinfo中有swoole了,但是php-m中看不到.定位到php.ini,添加了swoole.so模块,就提示 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/swoole.so' - /usr/lib64/php/modules/swoole.so: undefined symbol: zend_new_interned_string in Unknown on line 0

  • 问天涯

    使用pecl安装成功

  • 问天涯

    yum install php

    yum install php-pear yum install php-devel pecl install swoole vi /etc/php.ini php -m|grep swoole

  • 战神悟空

    出现错误: PHP Warning: PHP Startup: Unable to load dynamic library '/webserver/php/lib/php/extensions/no-debug-non-zts-20131226/swoole.so' - /webserver/php/lib/php/extensions/no-debug-non-zts-20131226/swoole.so: cannot open shared object file: No such file or directory in Unknown on line 0

    解决方案: 直接创建目录,重新安装即可

  • 爱在拜城_sunbea

    我没有执行这个cd swoole phpize ./configure make sudo make install 直接将swoole扩展安装好了 ,没得问题吧?

  • cjj

    安装的时候依赖 pcre, centos yum install pcre-devel

  • rhythm

    安装完毕!

  • 月半文一刀

    有个命令,php --ini能打印加载的所有ini配置文件