Home PHP Framework ThinkPHP Think-Swoole tutorial installation

Think-Swoole tutorial installation

Sep 14, 2020 am 09:27 AM
think-swoole

Swoole is an extension of PHP, so installing Swoole is essentially installing a PHP extension. Swoole only supports three operating systems: Linux, FreeBSD, and MacOS.

Recommended tutorials: "thinkphp" "swoole tutorial"

Installation preparation

Before installation You must ensure that the following software has been installed on the system

php-7.1 或更高版本
gcc-4.8 或更高版本
make
autoconf
Copy after login

Generally, the first three have been installed, and the autoconf tool needs to be installed.

Linux:yum install autoconf
Mac:brew install autoconf
Copy after login

Install the Swoole extension for PHP

1. Download Swoole

Download address: https://github.com/swoole/swoole-src /releases

Under normal circumstances, download the latest version.

2. Unzip it into the PHP extension directory. For example, my decompression path is:

/Applications/MAMP/bin/php/php7.2.10/include/php/ext/
Copy after login

The decompressed directory can be named swoole.

3. Enter the decompressed swoole directory and execute the phpize command. If the command is not added to the environment variable, you can execute the absolute path

sudo /Applications/MAMP/bin/php/php7.2.10/bin/phpize
Copy after login

Since there are multiple PHPs on my computer version, so I specified the version I'm using now to execute the command.

Command path: /php installation directory/bin/phpize

4. Execute command:

./configure --with-php-config=/Applications/MAMP/bin/php/php7.2.10/bin/php-config --enable-openss --enable-http2
Copy after login

The specific path is modified according to the actual situation.

5. After executing the command:

make && make install
Copy after login

After success, the installation address will appear. For example, my address is:

/Applications/MAMP/bin/php/php7.2.10/lib/php/extensions/no-debug-non-zts-20170718/
Copy after login

Enter this directory and see if there is swoole in it. so.

6. Add the swoole extension to php.ini.

Be sure to select the currently used PHP version configuration file, which can be viewed using the php --ini command. Mine is at:

/Applications/MAMP/bin/php/php7.2.10/conf/php.ini
Copy after login

Open the php.ini file and add the extension:

extension=”/Applications/MAMP/bin/php/php7.2.10/lib/php/extensions/no-debug-non-zts-20170718/swoole.so”
Copy after login

If you use the MAMP integrated environment, in addition to modifying the above php.ini file, you also need to modify the integrated environment dynamic configuration php.ini file, you can click the arrow after the version in the php option of the panel, or File -> Edit Template -> PHP -> PHP 7.xx -> php.ini to modify it.

7. After the installation is complete, execute the command:

php -m
Copy after login

to see if there is a swoole module in the list. If so, the installation is successful.

Execute the php --ri swoole command to view swoole related information.

8. Test

Enter the following path, and modify it according to the actual situation:

/Applications/MAMP/bin/php/php7.2.10/include/php/ext/swoole/examples/server
Copy after login

There is an echo.php file in it. After opening it, you will see a line of code:

$serv = new swoole_server("0.0.0.0", 9501);
Copy after login

means to listen to all IPs, the port number is 9501.

In the command line, enter the command:

php echo.php
Copy after login

If the command is being executed, there is no cursor, and no error is reported, then create a new command window and enter the following command:

Linux:
netstat -anp | grep 9501
Mac:
ps -ef | grep 9501
Copy after login

You can see that this process is already executing and has a pid process number. The test is successful!

Install the Think-Swoole extension in the ThinkPHP framework

After the PHP extension is installed, you need to install the extension in the framework.

First, we need to download the ThinkPHP framework (Think-Swoole extension currently supports ThinkPHP 5.1 and ThinkPHP 6. In order to demonstrate some new functions, the latest ThinkPHP 6 framework will be used in subsequent articles), and then go to the framework Execute the Think-Swoole installation command in the root directory:

ThinkPHP 5.1 installation command

ThinkPHP 6 installation command

After the installation is completed, execute the command:

php think swoole
Copy after login

If you see the prompt in the picture below, the plug-in can be used normally:

Think-Swoole tutorial installation

Error 1:

I reported an error when I installed and executed the above command, check An error message shows that the Xdebug plug-in cannot be used, so just close it. In the MAMP environment, it can be turned off directly in the php options.

Error 2:

[Swoole\Exception]
failed to listen server port[127.0.0.1:80], Error: Permission denied[13]
Copy after login

Open app/config/swoole.php, you can see that the port corresponds to port 80, because in Linux and Mac, only super administrators have ports 1024 and below. Use permissions, so you can change the port to 9501 (the default host is 127.0.0.1, which means monitoring the local address, here it is changed to 0.0.0.0, which means monitoring all addresses).

After the swoole service is turned on, let’s test it. Enter 127.0.0.1:9501 in the browser, and you can access it normally:

Think-Swoole tutorial installation

At the same time, this also shows that, Swoole comes with HTTP Server, which helps us open an http service, which is equivalent to Apache and Nginx.

At this point, the Think-Swoole plug-in installation is completed.

The above is the detailed content of Think-Swoole tutorial installation. For more information, please follow other related articles on the PHP Chinese website!

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

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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Performance optimization and debugging of TP6 Think-Swoole RPC service Performance optimization and debugging of TP6 Think-Swoole RPC service Oct 12, 2023 am 11:16 AM

Performance optimization and debugging of TP6Think-SwooleRPC service 1. Introduction With the rapid development of the Internet, distributed computing has become an indispensable part of modern software development. In distributed computing, RPC (RemoteProcedureCall, Remote Procedure Call) is a commonly used communication mechanism through which method calls across the network can be implemented. Think-Swoole, as a high-performance PHP framework, can support RPC services well. but

High scalability and distributed deployment of TP6 Think-Swoole RPC service High scalability and distributed deployment of TP6 Think-Swoole RPC service Oct 12, 2023 am 11:07 AM

TP6 (ThinkPHP6) is an open source framework based on PHP, which has the characteristics of high scalability and distributed deployment. This article will introduce how to use TP6 with Swoole extension to build a highly scalable RPC service, and give specific code examples. First, we need to install TP6 and Swoole extensions. Execute the following command in the command line: composerrequiretopthink/thinkpeclinstallswo

Highly concurrent request processing and scheduling of TP6 Think-Swoole RPC service Highly concurrent request processing and scheduling of TP6 Think-Swoole RPC service Oct 12, 2023 pm 12:33 PM

Highly concurrent request processing and scheduling of TP6Think-SwooleRPC service With the continuous development of Internet technology, concurrent request processing and scheduling of network applications has become an important challenge. In the TP6 framework, the Think-Swoole extension can be used to implement high-concurrency request processing and scheduling of the RPC (RemoteProcedureCall) service. This article will introduce how to build a Think-Swoole-based RPC service in the TP6 framework and provide

Data encryption and identity authentication mechanism of TP6 Think-Swoole RPC service Data encryption and identity authentication mechanism of TP6 Think-Swoole RPC service Oct 12, 2023 am 11:29 AM

Data encryption and identity authentication mechanism of TP6Think-SwooleRPC service With the rapid development of the Internet, more and more applications need to make remote calls to realize data interaction and function calls between different modules. In this context, RPC (RemoteProcedureCall) has become an important communication method. The TP6Think-Swoole framework can implement high-performance RPC services. This article will introduce how to use data encryption and identity authentication.

Security protection and authorization verification of TP6 Think-Swoole RPC service Security protection and authorization verification of TP6 Think-Swoole RPC service Oct 12, 2023 pm 01:15 PM

Security protection and authorization verification of TP6Think-SwooleRPC service With the rise of cloud computing and microservices, remote procedure call (RPC) has become an essential part of developers' daily work. When developing RPC services, security protection and authorization verification are very important to ensure that only legitimate requests can access and call the service. This article will introduce how to implement security protection and authorization verification of RPC services in the TP6Think-Swoole framework. 1. Basic concepts of RPC services

TP6 Think-Swoole's RPC service and message queue integration and application TP6 Think-Swoole's RPC service and message queue integration and application Oct 12, 2023 am 11:37 AM

Integration and application of TP6Think-Swoole's RPC service and message queue In modern software development, RPC service (RemoteProcedureCall) and message queue are common technical means used to implement service calls and asynchronous message processing in distributed systems. Integrating Think-Swoole components in the TP6 framework can easily implement the functions of RPC services and message queues, and provides concise code examples for developers to understand and apply. 1. RPC

Performance testing and performance tuning of TP6 Think-Swoole RPC service Performance testing and performance tuning of TP6 Think-Swoole RPC service Oct 12, 2023 pm 02:19 PM

Performance testing and performance tuning of TP6Think-SwooleRPC service 1. Introduction With the rapid development of the Internet, the application of distributed systems is becoming more and more widespread. In distributed systems, RPC (Remote Procedure Call) is a common communication mechanism, which allows services on different nodes to call each other and achieve collaborative work in distributed systems. In the TP6 framework, Think-Swoole, as a high-performance Swoole driver, provides convenient RPC service support. This article mainly introduces T

TP6 RPC service and microservice architecture practice cases built by Think-Swoole TP6 RPC service and microservice architecture practice cases built by Think-Swoole Oct 12, 2023 pm 12:04 PM

Introduction to the practical case of RPC service and microservice architecture built by TP6Think-Swoole: With the rapid development of the Internet and the expansion of business scale, the traditional monolithic architecture can no longer meet the needs of large-scale business scenarios. Therefore, the microservice architecture came into being. In the microservice architecture, the RPC (RemoteProcedureCall) service is an important way to achieve communication between services. Through RPC services, various microservices can call each other conveniently and efficiently. In this article

See all articles