Enables PHP developers to write high-performance, scalable, concurrent TCP, UDP, Unix socket, HTTP, Websocket services in PHP programming language without too much knowledge about non-blocking I/O programming and low-level Linux kernel. Compared with other async programming frameworks or softwares such as Nginx, Tornado, Node.js, Swoole has the built-in async, multiple threads I/O modules. Developers can use sync or async API to write the applications — www.swoole.co.uk
Siler\Swoolenamespace get you covered.
docker-compose upor just
php index.phpif you're not using Docker.
http://<docker_machine_ip>:9051and you should get a "Hello World" response as plain/text.
Swoole\emit('Not found', 404)at the end?".
Siler\Swoole\emit()function will short-circuit further emit attempts, so it will work exactly like you have imagined, when a route matches a path like
/it will emit the proper response, but when no route matches and this means: no route will emit something, then
Swoole\emit('Not found', 404)will emit a 404 Not found response.
Siler\Swoole\httpfunction returns a plain
Swoole\Http\Serverso you can give it to a variable and use regular methods from Swoole's documentation like
json(), Siler will automatically add the Content-type: application/json response header. Also you can enable CORS.