Home > PHP Framework > Swoole > Detailed tutorial on installing Swoole in PHP7

Detailed tutorial on installing Swoole in PHP7

angryTom
Release: 2019-11-25 16:25:52
forward
2876 people have browsed it

Detailed tutorial on installing Swoole in PHP7

Environment

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

Download swoole

First download the swoole source code package, this operation is very Simple, not much to say.

wget -c https://github.com/swoole/swoole-src/archive/v2.0.6.tar.gz
Copy after login

Unzip:

tar -zxvf v2.0.6.tar.gz
cd swoole-src-2.0.6/
Copy after login

Compile & Install

Use phpize to generate php compilation configuration

./configure to compile Configuration detection

make to compile, 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
Copy after login

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/
Copy after login

This means that the swoole.so file was successfully generated in the /usr/lib64/php/modules/ directory

Modify the configuration file

To be able to use the module, You also need to add this module in the php.ini file.

It should be noted here that the module configuration files of php7 are separated separately.

The following content can be found in php.ini

;;;; 
; Note: packaged extension modules are now loaded via the .ini files 
; found in the directory /etc/php.d; these are loaded by default. 
;;;;
Copy after login

Therefore, if your php is installed without special settings, you can find the added module in the /etc/php.d directory configuration file.

Enter the cd /etc/php.d directory and complete the relevant configuration

[root@php7 swoole-src-2.0.6]# vim swoole.ini
Copy after login
; Enable swoole extension module
extension=swoole.so
Copy after login

Restart the service

After adding the php module, you need to restart It will take effect only after starting the service. If sometimes it still doesn't work after restarting, please close it first and then restart it.

[root@php7 swoole-src-2.0.6]# systemctl restart nginx
[root@php7 swoole-src-2.0.6]# systemctl restart php-fpm
Copy after login

Check whether swoole is successfully loaded through php -m or phpinfo()

Automatic prompt of swoole code

After installing the extension, it’s a matter of use. Since there is no code prompt, it is sometimes very inconvenient. Someone on github has provided ide-helper for swoole code prompts. The specific setting method is as follows:

Here is: phpStorme as an example, download the code to the local

git clone git@github.com:eaglewu/swoole-ide-helper.git ide-helper
Copy after login

After the above steps, you can use swoole in phpStorme. And provide code tips.

Simple test

All test codes are placed here

Please clone the code locally to facilitate observation of the effect.

git clone git@github.com:helei112g/learn-swoole.git
Copy after login

The code example demo1-serv provided in this section

Enter the test code directory,

Then use telnet on the server to test

First, run the server-side listening program

php demo1-serv.php
Copy after login

After executing this command, the server will display:

Client: Connect.
Copy after login

Open another terminal and use telnet to connect to the current server-side listening port. And enter some text and observe the changes in the terminal.

[root@php7 ~]# telnet 127.0.0.1 9999
Copy after login
Hi!
Server: Hi!
Copy after login

This is just a simple simulated reply. Whatever the client sends, the server responds.

Exit telnet and observe what the server will display

Close the window directly, or:

[root@php7 ~]# Ctrl+]
[root@php7 ~]# telnet> quit
Copy after login

At this time, you will see on the service side:

Client: Close.
Copy after login

PS: If telnet is not installed in the test environment, please google to install it yourself.

PHP Chinese website, a large number of free swoole introductory tutorials, welcome to learn online!

The above is the detailed content of Detailed tutorial on installing Swoole in PHP7. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template