Swoole is an asynchronous, parallel, high-performance network communication engine in PHP, supporting TCP long connections, Websocket, Mqtt and other protocols. It is widely used in the development of mobile apps, mobile game servers, online game servers, chat rooms, hardware communications, smart homes, Internet of Vehicles, Internet of Things and other fields. The following editor introduces the installation process in detail.
It’s been a long time since I’ve updated. It’s not that I’m lazy, it’s that I’m too busy! Finally got a few days of free time.
During this period, I am going to bring you an introductory tutorial on swoole to feel the power of nodeJs in php.
All sample codes are placed on github: learn-swoole
Apache is not used as the web server here. Use nginx php-fpm, which has more powerful performance and easier configuration. And in order to keep up with the pace of PHP, a relatively new PHP version is also used
[x] centos7
[x] php7.0.12
[x] nginx/1.10.2
[x] php-fpm
First download the source code package of swoole. This operation is very simple and there is not much to say.
wget -c https://github.com/swoole/swoole-src/archive/v2.0.6.tar.gz 解压: tar -zxvf v2.0.6.tar.gz cd swoole-src-2.0.6/
Use phpize to generate php compilation configuration
./configure to do compilation configuration detection
make Compile and make install to install
Command execution:
[root@php7 swoole-src-2.0.6]# phpize [root@php7 swoole-src-2.0.6]# ./configure [root@php7 swoole-src-2.0.6]# make && make install
After make install, if correct, the following content will appear
[root@php7 swoole-src-2.0.6]# make install Installing shared extensions: /usr/lib64/php/modules/
This means that in /usr/lib64/ In the php/modules/ directory, the swoole.so file was successfully generated
To be able to use this module, you also need to add it to the php.ini file this module.
It should be noted here that the module configuration files of php7 are separated separately.
The following content can be found in php.ini
Therefore, if your php is installed, If there is no special setting, you can find the configuration file for adding the module in the /etc/php.d directory. Enter the cd /etc/php.d directory and complete the relevant configuration;;;;
; Note: packaged extension modules are now loaded via the .ini files
; found in the directory /etc/php.d; these are loaded by default.
##;;;;
[root@php7 swoole-src-2.0.6]# vim swoole.ini ; Enable swoole extension module extension=swoole.so
[root@php7 swoole-src-2.0.6]# systemctl restart nginx [root@php7 swoole-src-2.0.6]# systemctl restart php-fpm
git clone git@github.com:eaglewu/swoole-ide-helper.git ide-helper
git clone git@github.com:helei112g/learn-swoole.git
php demo1-serv.php
Client: Connect.
[root@php7 ~]# telnet 127.0.0.1 9999Hi!Server: Hi!
[root@php7 ~]# Ctrl+] [root@php7 ~]# telnet> quit
Client: Close.PS: If telnet is not installed in the test environment, please google to install it yourself. Recommended learning:
The above is the detailed content of How to install Swoole in PHP7. For more information, please follow other related articles on the PHP Chinese website!