Swoole is an high-performance network framework using an event-driven, asynchronous, non-blocking I/O model and coroutine.
Swoole is designed for building large scale concurrency systems. It is written in C/C++ and installed as a PHP extension.
PHP developers can use Swoole to write high-performance, scalable, concurrent TCP, UDP, Unix Socket, HTTP, WebSocket services with PHP syntax. Don't have to know too much about non-blocking I/O programming and low-level Linux kernel.
Compared with other Async programming frameworks or software such as Nginx, Tornado, Node.js, Swoole is a PHP Async solution has the built-in async, coroutine support, multiple threads I/O modules.
Developers can use Sync or Async API to write the applications.
Swoole PHP network framework enhances the efficiency of the R&D team, enable them to focus on the development of innovative products.
Swoole follows the similar principle 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.
<?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.