search
HomeBackend DevelopmentPHP7How to install Swoole in PHP7

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.

How to install Swoole in PHP7

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

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 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/

Compilation & Installation

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

Modify the configuration file

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

;;;;

; Note: packaged extension modules are now loaded via the .ini files

; found in the directory /etc/php.d; these are loaded by default.

##;;;;

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

[root@php7 swoole-src-2.0.6]# vim swoole.ini

; Enable swoole extension module
extension=swoole.so

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

Use php -m or phpinfo() to check whether swoole is successfully loaded

How to install Swoole in PHP7

Automatic prompt for swoole code

Installed After expansion, it is 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:

Take: phpStorme as an example, download the code to the local

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

Set according to the picture content

How to install Swoole in PHP7

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

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
After executing this command, the server will display:

Client: Connect.

  • Open another terminal, use telnet to connect to the port that the current server is listening to, and enter some text to observe the changes in the terminal.

  • [root@php7 ~]# telnet 127.0.0.1 9999Hi!Server: Hi!
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

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

Client: Close.

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

Recommended learning:

php video tutorial

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!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.