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
Unzip:
tar -zxvf v2.0.6.tar.gz cd swoole-src-2.0.6/
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
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 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. ;;;;
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
; 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
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
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 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
Hi! 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.
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

If you have used Docker, you must understand daemons, containers, and their functions. A daemon is a service that runs in the background when a container is already in use in any system. Podman is a free management tool for managing and creating containers without relying on any daemon such as Docker. Therefore, it has advantages in managing containers without the need for long-term backend services. Additionally, Podman does not require root-level permissions to be used. This guide discusses in detail how to install Podman on Ubuntu24. To update the system, we first need to update the system and open the Terminal shell of Ubuntu24. During both installation and upgrade processes, we need to use the command line. a simple

Using Swoole coroutines in Laravel can process a large number of requests concurrently. The advantages include: Concurrent processing: allows multiple requests to be processed at the same time. High performance: Based on the Linux epoll event mechanism, it processes requests efficiently. Low resource consumption: requires fewer server resources. Easy to integrate: Seamless integration with Laravel framework, simple to use.

While studying in high school, some students take very clear and accurate notes, taking more notes than others in the same class. For some, note-taking is a hobby, while for others, it is a necessity when they easily forget small information about anything important. Microsoft's NTFS application is particularly useful for students who wish to save important notes beyond regular lectures. In this article, we will describe the installation of Ubuntu applications on Ubuntu24. Updating the Ubuntu System Before installing the Ubuntu installer, on Ubuntu24 we need to ensure that the newly configured system has been updated. We can use the most famous "a" in Ubuntu system

Detailed steps to install Go language on Win7 computer Go (also known as Golang) is an open source programming language developed by Google. It is simple, efficient and has excellent concurrency performance. It is suitable for the development of cloud services, network applications and back-end systems. . Installing the Go language on a Win7 computer allows you to quickly get started with the language and start writing Go programs. The following will introduce in detail the steps to install the Go language on a Win7 computer, and attach specific code examples. Step 1: Download the Go language installation package and visit the Go official website

Installing Go language under Win7 system is a relatively simple operation. Just follow the following steps to successfully install it. The following will introduce in detail how to install Go language under Win7 system. Step 1: Download the Go language installation package. First, open the Go language official website (https://golang.org/) and enter the download page. On the download page, select the installation package version compatible with Win7 system to download. Click the Download button and wait for the installation package to download. Step 2: Install Go language

Swoole and Workerman are both high-performance PHP server frameworks. Known for its asynchronous processing, excellent performance, and scalability, Swoole is suitable for projects that need to handle a large number of concurrent requests and high throughput. Workerman offers the flexibility of both asynchronous and synchronous modes, with an intuitive API that is better suited for ease of use and projects that handle lower concurrency volumes.

To restart the Swoole service, follow these steps: Check the service status and get the PID. Use "kill -15 PID" to stop the service. Restart the service using the same command that was used to start the service.

Performance comparison: Throughput: Swoole has higher throughput thanks to its coroutine mechanism. Latency: Swoole's coroutine context switching has lower overhead and smaller latency. Memory consumption: Swoole's coroutines occupy less memory. Ease of use: Swoole provides an easier-to-use concurrent programming API.
