Swoole Documentation and Swoole Wiki

What is Swoole?

Swoole is a high-performance network framework based on an event-driven, asynchronous, non-blocking I/O coroutine programming model for PHP.

Designed for building large scale concurrency systems. It is written in C/C++ and installed as a PHP extension. Enabling PHP developers to write code in a more efficient manner, taking advantage of event-loops and fibers/coroutines.

Providing you with an easy to use coroutine API and allowing you to use existing libraries within the PHP ecosystem.

What can I do with Swoole?

PHP developers can use Swoole to write high-performance, scalable, concurrent TCP, UDP, Unix Socket, HTTP, WebSocket, FastCGI services with PHP syntax. You Don't have to be an expert on non-blocking I/O programming and low-level Linux kernel development to take advantage of what Swoole offers.

Compared with other Async programming frameworks or software such as Nginx, Tornado, Node.js, Swoole is a complete PHP Async solution that has built-in support for async programming via coroutines, a range of multi-threaded I/O modules (HTTP Server, WebSockets, TaskWorkers, Process Pools) and support for popular PHP clients like PDO for MySQL, Redis and CURL.

With the power and performance Swoole brings you can write scalable PHP applications for web servers, API backends, game servers, chat systems, CMS platforms, micro-services and realtime web services etc.

What are the differences?

Developers can wite PHP code using a Synchronous or Asynchronous programming model and not have to rely on callback hell because of how Swoole achieves concurrency with coroutines, a much easier way to write Asynchronous code in a Synchronous style.

Swoole enhances the efficiency of your PHP applications and brings you out of the traditional stateless model, enabling you to focus on the development of innovative products at high scale, brining event loops and asynchronous programming to the PHP language.

Swoole follows similar asynchronous principles from Erlang, Node.js and Netty, but for PHP.

The Swoole framework is released as a PHP extension (PECL) and runs as a PHP CLI application, you can either run a Swoole HTTP server directly on your network or use Apache or Nginx and a proxy pass through to your Swoole enabled application.

Hello world

<?php
use Swoole\Http\Server;
use Swoole\Http\Request;
use Swoole\Http\Response;

$server = new Swoole\HTTP\Server("127.0.0.1", 9501);

$server->on("start", function (Server $server) {
    echo "Swoole http server is started at http://127.0.0.1:9501\n";
});

$server->on("request", function (Request $request, Response $response) {
    $response->header("Content-Type", "text/plain");
    $response->end("Hello World\n");
});

$server->start();

Interested with Swoole? Get Started with Swoole now!

You can also check the Swoole Error Codes.

Documentation

Server
PHP Coroutine
Coroutine Clients
Multiprocessing

Have more questions or need support? - Checkout the community page or the Swoole Quick Start guide. We even have a Support Service as well.