Home >Backend Development >PHP Problem >How to install swoole on Mac system
How to install swoole on Mac system
Swoole is a high-performance network communication library based on PHP language. Compared with the traditional PHP-FPM mode, it has higher performance and better performance in network communication scenarios. Concurrency capabilities. It is an open source project and has a stable community that can provide rich technical support and ecological environment. This article will introduce how to install swoole under Mac system.
Step One: Install Homebrew
Homebrew is the package management system of OS X, which can easily install some open source software packages and libraries. Before you start installing swoole, you need to install Homebrew. Enter the following command in the command line terminal to install Homebrew:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Step 2: Install PHP
Swoole is a PHP extension, so PHP needs to be installed first. Enter the following command in the command line to install PHP:
$ brew install php
Step 3: Install swoole
After installing PHP, you need to enter the following command in the command line terminal to install swoole:
$ pecl install swoole
If you are prompted that PECL is not installed, you need to install PECL first:
$ brew install pear
After installing swoole, you need to add the swoole extension to the PHP configuration file. Enter the following command in the command line terminal to open the PHP configuration file:
$ nano /usr/local/etc/php/7.1/php.ini
Add the following text at the end of the file:
[swoole] extension=/usr/local/Cellar/php/7.1.9/pecl/20160303/swoole.so
Needs to be modified according to the actual installation path. Save the configuration file and exit the nano editor.
Step 4: Test whether swoole is installed successfully
Enter the following command in the command line terminal to test whether swoole is installed successfully:
$ php -m | grep swoole
If swoole is output, it means swoole Installed successfully.
Step 5: Use swoole
After installing swoole, you can use swoole in PHP code. Here is a simple example:
<?php $server = new Swoole\Http\Server("127.0.0.1", 9501); $server->on('Request', function ($request, $response) { $response->header("Content-Type", "text/plain"); $response->end("Hello World\n"); }); $server->start();
Save the code into a PHP file, such as server.php. Enter the following command in the command line terminal to start server.php:
$ php server.php
Open the browser, enter http://localhost:9501, you should be able to see the words "Hello World" page.
Summary:
This article introduces the steps to install swoole under Mac system, including installing Homebrew, PHP and swoole, and how to test whether swoole is successfully installed and use swoole. I hope this article can help developers who want to use swoole.
The above is the detailed content of How to install swoole on Mac system. For more information, please follow other related articles on the PHP Chinese website!