How to install swoole on Mac system

PHPz
Release: 2023-03-29 11:17:45
Original
2018 people have browsed it

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)"
Copy after login

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

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

If you are prompted that PECL is not installed, you need to install PECL first:

$ brew install pear
Copy after login

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

Add the following text at the end of the file:

[swoole]
extension=/usr/local/Cellar/php/7.1.9/pecl/20160303/swoole.so
Copy after login

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

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();
Copy after login

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

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!

source:php.cn
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