Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Swoole compiles the installation


May 14, 2021 Swoole


Table of contents


Swoole compiles the installation steps

The Swoole extension was built according to the php standard extension. Use phpize to generate php compilation configuration, ./configure to do compilation configuration detection, make to compile, make install to install.

  • Download the reales version of swoole and pull the latest code directly from the github trunk
  • If the current user is not root, you may not have write permissions for the php directory, which requires sudo or su at installation time
  • If you are updating the code directly on the git branch, be sure to perform make clean before recompiling

The installation is ready

Before installing swoole, you must ensure that the following software is installed in the system

php-5.3.10 或更高版本
gcc-4.4 或更高版本
make
autoconf

Download the address

After downloading the source code package, enter the source directory at the terminal and execute the following commands for compilation and installation

cd swoole
phpize
./configure
make 
sudo make install

(Note: swoole's ./configuration has a lot of extra parameters that can be viewed through the ./--help command, where only the async-mysql item is open, and the others are selected by default) Here are the additional parameters for the ./configure compilation configuration to turn on certain features

1.8.7 or later no longer requires settings -- enable-async-mysql and --enable-async-httpclient, async_mysql and async_httpclient built-in
--enable-swoole-debug
Turn on the debug log, and when you turn this option on, the swoole will print the debug log for all kinds of details. Do not enable the production environment.
--enable-sockets
Increase support for sockets resources, relying on sockets extensions. Turning this parameter on swoole_event_add you can add the socket extension to create an event loop connected to the swoole.
--enable-async-mysql
Add asynchronous mysql support, relying on mysqli and mysqlnd extensions.
--enable-async-redis
Add asynchronous Redis client support, relying on thehiredis library
--enable-async-httpclient
Increase asynchronous Http and WebSocket client support
--enable-ringbuffer
Turn on the BingBuffer memory pool
This setting is experimental in nature and is primarily used to improve performance, so do not turn it on in the production environment
--enable-openssl
Enable SSL support

PECL

The swoole project has been included in PHP's official extension library, in addition to manual download compilation, you can also use PHP official peck command, one-click download installation of swoole

pecl install swoole

Configure php .ini

After the compilation installation is successful, modify the php .ini join

extension=swoole.so

Use php -m or phpinfo() to see if the swoole was successfully loaded, and if it is not possible that the path to php.ini is not correct, you can use php -i-|grep php.ini to locate the absolute path to php.ini


Information viewed via phpinfo() after successful installation:
Swoole compiles the installation

Common errors in installation

make or make install could not be executed or compiled incorrectly

NOTICE: PHP message: PHP Warning: PHP Startup: swoole: Unable to initialize module
Module compiled with module API=20090626
PHP compiled with module API=20121212
These options need to match
in Unknown on line 0

The php version does not correspond to the phpize and php-config used at compile time and needs to be compiled using an absolute path. PhP is executed using an absolute path.

/usr/local/php-5.4.17/bin/phpize
./configure --with-php-config=/usr/local/php-5.4.17/bin/php-config
/usr/local/php-5.4.17/bin/php server.php

The mysql header file is missing

php_mysqli_structs.h:64:23: fatal error: my_global.h: No such file or directory

The header file for mysqlclient was not found and mysqlclient-dev needs to be installed

It is recommended that you compile your own php and do not use the php version that come with the Linux package management system

The pcre.h header file is missing

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

The reason is the lack of pcre, which requires the installation of libpcre

Cannot find autoconf

The phpize command requires an autoconf tool, please install it first.

make install failed

make install requires root permissions, if you are not logged in as root users, please use sudo or su, and then install.

After modifying the php .ini, there is no swoole in php -m or phpinfo

php -i|grep php.ini

Look at the loaded php .ini path to confirm that the correct php .ini.

Modify the php .ini, open the error display, and see if there is a startup error.

display_errors => On  
display_startup_errors => On

error: too many arguments to function 'zend_exception_error'

Your PHP version is lower than PHP-5.3.10, please upgrade the PHP version.

What if compilation fails?

Don't be discouraged, join our development group QQ group: 495864936, your problem will be solved within 24 hours.