Skip to content
This repository has been archived by the owner on Jul 15, 2020. It is now read-only.

Latest commit

 

History

History
40 lines (26 loc) · 1.06 KB

intro.md

File metadata and controls

40 lines (26 loc) · 1.06 KB

Introduction

Swoole is event-driven PHP extension with HTTP server, websocket server,

Swoole is an event-driven, asynchronous, concurrent networking communication engine with high performance PHP extension written in C language.

It includes components for different purposes: TCP/UDP Server and Client, Task Worker, Database Connection Pooling, Millisecond Timer, Event, Async IO, Async Http/WebSocket Client, Async Redis Client, Async MySQL Client, and Async DNS Requiring.

Prononuced s+wall - /swəʊl/.

Swoole installation

Installation can be done with PECL as any other PHP extension:

pecl install swoole

In case missing, add the extension=swoole.so to the php.ini for PHP CLI. Beware that there are multiple php.ini files.

Swoole HTTP Server

We'll start with running a simple HTTP server:

<?php

$http = new \swoole_http_server('127.0.0.1', 9501);

$http->on('request', function (\swoole_http_request $request, \swoole_http_response $response) {
    $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
});

$http->start();