Swoole Overview
https://www.youtube.com/watch?v=f_NBeaLX0Qo
Breve viaggio sulle possibilità offerte da un sistema asincrono e una overview sull'estensione Swoole e sui componenti offerti. Non mancheranno alcuni test di performance ma sopratutto risponderemo alla domanda: può Swoole sostituire NodeJs?
10. MAIN FEATURES
MAIN FEATURES
Event-driven, Coroutine, asynchronous programming for PHP
Async TCP / UDP / HTTP / Websocket / HTTP2 client/server side API
IPv4 / IPv6 / Unixsocket / TCP / UDP and SSL / TLS
Fast serializer / unserializer
Milliseconds task scheduler
Daemonize
High performance, scalable, support C1000K
11.
12. SO WHAT DO WE DO?
SO WHAT DO WE DO?
Chat/Webchat/bot
MQTT Broker
Push notification system
Web monitor system
Speedup laravel/symfony/lumen/slim/yii
Cron task scheduler
Backend for frontend
PHP-FPM client and Proxy
Web crawler
13.
14. SWOOLE HTTP SERVER
SWOOLE HTTP SERVER
$http = new SwooleHttpServer("0.0.0.0", 9501);
1
2
$http->on('request', function ($request, $response) {
3
$response->header("Content-Type", "text/plain");
4
$response->end("Hello Worldn");
5
});
6
7
$http->start();
8
15. SWOOLE HTTP SERVER
SWOOLE HTTP SERVER
$http = new SwooleHttpServer("0.0.0.0", 9501);
1
2
$http->on('request', function ($request, $response) {
3
$response->header("Content-Type", "text/plain");
4
$response->end("Hello Worldn");
5
});
6
7
$http->start();
8
$http->on('request', function ($request, $response) {
$response->header("Content-Type", "text/plain");
$response->end("Hello Worldn");
});
$http = new SwooleHttpServer("0.0.0.0", 9501);
1
2
3
4
5
6
7
$http->start();
8
16. SWOOLE HTTP SERVER
SWOOLE HTTP SERVER
$http = new SwooleHttpServer("0.0.0.0", 9501);
1
2
$http->on('request', function ($request, $response) {
3
$response->header("Content-Type", "text/plain");
4
$response->end("Hello Worldn");
5
});
6
7
$http->start();
8
$http->on('request', function ($request, $response) {
$response->header("Content-Type", "text/plain");
$response->end("Hello Worldn");
});
$http = new SwooleHttpServer("0.0.0.0", 9501);
1
2
3
4
5
6
7
$http->start();
8 $http->start();
$http = new SwooleHttpServer("0.0.0.0", 9501);
1
2
$http->on('request', function ($request, $response) {
3
$response->header("Content-Type", "text/plain");
4
$response->end("Hello Worldn");
5
});
6
7
8
32. COROUTINE
COROUTINE
Coroutines are computer program components
that generalize subroutines for non-preemptive multitasking
by allowing multiple entry points for suspending and resuming execution at certain
locations.
38. TABLE (KEY-VALUE STORE)
TABLE (KEY-VALUE STORE)
High performance: read/write speed >2 millions per second
Share variables across multiple threads or processes
Store counters in your application
60. PRODUCTION READY?
PRODUCTION READY?
Tencent
microservices, long-time connection
Baidu
high-performance app, performance data collection services, peak period 500,000 qps
JD.com
WebAPI, WebSocket
2345
real-time data push of PC-side, users online more than 10 million
"Legend of Sword"
RPG role-playing game server
61. CONS
CONS
Documentazione ufficiale delle API poco approfondita
Mancanza di esempi di applicazioni complesse
La stragrande maggioranze di documenti/case/video è in
Il workspace slack di Swoole ha ~300 membri (GrUSP ~1500)