search
HomePHP FrameworkSwooleHow to use swoole extension

How to use swoole extension

Dec 23, 2019 pm 02:27 PM
swoole

How to use swoole extension

Swoole is an extension of PHP that can be installed and enabled through PHP extension.

Local installation

Laradock

If you install it locally, taking Laradock as an example, you need to add the following two lines in .env in the laradock directory Set the configuration value to true:

WORKSPACE_INSTALL_SWOOLE=true
PHP_FPM_INSTALL_SWOOLE=true

Then run docker-compose build php-fpm workspace to rebuild the Docker container. After the build is completed, restart the two containers, enter the workspace container, and run php -m to check whether Swoole is installed successfully. , if the extension list contains swoole, the installation is successful.

Windows/Mac

If it is installed on a local Windows/Mac system, directly execute the following command to install the interface:

pecl install swoole

Simple use:

HTTP Server

First we write a simple HTTP server through Swoole, create a http_server.php file in the test directory, and write the file code as follows:

<?php

// 表明服务器启动后监听本地 9051 端口
$server = new swoole_http_server(&#39;127.0.0.1&#39;, 9501);

// 服务器启动时返回响应
$server->on("start", function ($server) {
    echo "Swoole http server is started at http://127.0.0.1:9501\n";
});

// 向服务器发送请求时返回响应
// 可以获取请求参数,也可以设置响应头和响应内容
$server->on("request", function ($request, $response) {
    $response->header("Content-Type", "text/plain");
    $response->end("Hello World\n");
});

// 启动 HTTP 服务器
$server->start();

In this way, a most basic The HTTP server is completed. Its working principle is similar to that of industrial-grade Apache and Nginx servers, except that it provides the simplest server monitoring and response functions. We enable this server in the terminal:

How to use swoole extension

This means that the server has been started and is listening for requests. Go to http://127.0.0.1:9501 in the browser to get the server output response content:

How to use swoole extension Recommended learning: swoole video tutorial

The above is the detailed content of How to use swoole extension. For more information, please follow other related articles on the PHP Chinese website!

Statement
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

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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