SWOOLE PHP
Ant
2018-03-30
2/39
Introduction
3/39
Swoole is a C extension for PHP
Apache-2.0
+ =
4/39
Ref: https://www.swoole.co.uk/
5/39
Ref: https://www.swoole.co.uk/
6/39
Architecture
7/39
Ref: https://www.yanshuo.me/p/11565
Apache / Nginx + PHP-FPM Swoole
8/39
Ref: https://www.spaceotechnologies.com/why-node-js-best-option-develop-chat-based-mobile-application/
Multi-threaded (Java) Single-thread / Event loop (Node)
9/39
Ref: http://slides.com/albertcht/swoole-redefine-php#/3/6
Multi-threaded (Java) Nginx with PHP-FPM
10/39
Ref: http://slides.com/albertcht/swoole-redefine-php#/3/6
Multi-threaded (Java) Nginx with PHP-FPM
PHP-FPM is PHP FastCGI Process Manager
11/39
Ref: http://ae.koroglu.org/nginx-with-php-fpm-on-centos-6/
PHP Files
Nginx with PHP-FPM
12/39
Ref: http://ae.koroglu.org/nginx-with-php-fpm-on-centos-6/
PHP Files
Nginx with PHP-FPM Swoole
PHP Files
13/39
Example
14/39
Swoole Installation
Ref: https://www.swoole.co.uk/
15/39
Swoole HTTP Server
Ref: https://www.swoole.co.uk/
16/39
Swoole WebSocket Server
Ref: https://www.swoole.co.uk/
17/39
Swoole TCP Server
Ref: https://www.swoole.co.uk/
18/39
Swoole TCP Client
Ref: https://www.swoole.co.uk/
19/39
Swoole Async
Ref: https://www.swoole.co.uk/
20/39
Ref: https://www.swoole.co.uk/
Swoole Task
21/39
Performance
22/39
Performance
Demo
23/39
Connection pool
24/39
Ref: https://docs.oracle.com/cd/B28359_01/appdev.111/b28395/oci09adv.htm#LNOCI87728
Connection pool
➊ Reduces the number of times new connection objects are created.
➋ Promotes connection object reuse.
➌ Quickens the process of getting a connection.
➍ Minimizes the number of stale connections.
25/39
Ref: http://ae.koroglu.org/nginx-with-php-fpm-on-centos-6/
Swoole
PHP Files
26/39
Ref: http://ae.koroglu.org/nginx-with-php-fpm-on-centos-6/
Swoole
PHP Files
DBconnDBconn
27/39
Ref: http://ae.koroglu.org/nginx-with-php-fpm-on-centos-6/
Swoole
PHP Files
DBconn TaskDBconn
28/39
Ref: http://ae.koroglu.org/nginx-with-php-fpm-on-centos-6/
Swoole
PHP Files
DBconn Task
vendor/autoload.php
DBconn
29/39
Async
30/39
Ref: https://wiki.swoole.com/wiki/page/517.html
Async MySQL Client
$db = new swoole_mysql;
$server = array(
'host' => '192.168.1.1',
'port' => 3306,
'user' => 'test',
'password' => 'test',
'database' => 'test',
'charset' => 'utf8',
);
$db->connect($server, function ($db, $r) {
if ($r === false) {
var_dump($db->connect_errno, $db->connect_error);
die;
}
$db->query('show tables', function(swoole_mysql $db, $r) {
if ($r === false)
{
var_dump($db->error, $db->errno);
}
elseif ($r === true )
{
var_dump($db->affected_rows, $db->insert_id);
}
var_dump($r);
$db->close();
});
});
31/39
32/39
Memory leaking !!
33/39
Memory leaking !!
34/39
Ref: https://github.com/guzzle/guzzle/issues/1407
35/39
Coroutine
36/39
Ref: https://wiki.swoole.com/wiki/page/604.html
Coroutine: HTTP Client
$httpclient = new SwooleCoroutineHttpClient('127.0.0.1', 80);
$httpclient->setHeaders(['Host' => "api.mp.qq.com"]);
$httpclient->set([ 'timeout' => 1]);
$httpclient->setDefer();
$httpclient->get('/');
// to do something
$http_res = $httpclient->recv();
37/39
Why not Go(lang)
38/39
Why not Go(lang)
➊ Not most developers in company are familiar with Go(lang).
➋ Not so many Go(lang) developers in Taiwan (future?).
➌ Training time.
➍ Swoole performance is close to Go(lang) in some cases.
39/39
yftzeng@gmail.com
https://www.facebook.com/yftzeng.tw
https://twitter.com/yftzeng

More Related Content

PDF
How to Build a High Performance Application with PHP and Swoole?
PPTX
Overlapped IO와 IOCP 조사 발표
PDF
Windows IOCP vs Linux EPOLL Performance Comparison
PDF
게임서버프로그래밍 #1 - IOCP
PDF
gRPC with java
PDF
게임서버프로그래밍 #4 - 멀티스레드 프로그래밍
PDF
Iocp 기본 구조 이해
PDF
Ndc2014 시즌 2 : 멀티쓰레드 프로그래밍이 왜 이리 힘드나요? (Lock-free에서 Transactional Memory까지)
How to Build a High Performance Application with PHP and Swoole?
Overlapped IO와 IOCP 조사 발표
Windows IOCP vs Linux EPOLL Performance Comparison
게임서버프로그래밍 #1 - IOCP
gRPC with java
게임서버프로그래밍 #4 - 멀티스레드 프로그래밍
Iocp 기본 구조 이해
Ndc2014 시즌 2 : 멀티쓰레드 프로그래밍이 왜 이리 힘드나요? (Lock-free에서 Transactional Memory까지)

What's hot (20)

PDF
Ethereum virtual machine for Developers Part 1
PDF
PostgreSQL Extensions: A deeper look
PDF
Iocp advanced
PDF
OpenAPI and gRPC Side by-Side
PPTX
Introduce of open swoole
PDF
Windows Registered I/O (RIO) vs IOCP
PDF
[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍
PDF
Dexador Rises
PDF
홍성우, 게임 서버의 목차 - 시작부터 출시까지, NDC2019
PDF
실시간 게임 서버 최적화 전략
PPTX
[NDC17] Kubernetes로 개발서버 간단히 찍어내기
PPT
GCGC- CGCII 서버 엔진에 적용된 기술 (1)
PDF
[COSCUP 2022] 讓黑畫面再次偉大 - 用 PHP 寫 CLI 工具
PDF
[IGC 2017] 아마존 구승모 - 게임 엔진으로 서버 제작 및 운영까지
PPTX
스마트폰 온라인 게임에서 고려해야 할 것들
PDF
DeathNote of Microsoft Windows Kernel
PDF
시작하자 단위테스트
PPTX
Ndc14 분산 서버 구축의 ABC
PDF
Tuning Speculative Retries to Fight Latency (Michael Figuiere, Minh Do, Netfl...
PPTX
Postman Collection Format v2.0 (pre-draft)
Ethereum virtual machine for Developers Part 1
PostgreSQL Extensions: A deeper look
Iocp advanced
OpenAPI and gRPC Side by-Side
Introduce of open swoole
Windows Registered I/O (RIO) vs IOCP
[KGC 2012]Boost.asio를 이용한 네트웍 프로그래밍
Dexador Rises
홍성우, 게임 서버의 목차 - 시작부터 출시까지, NDC2019
실시간 게임 서버 최적화 전략
[NDC17] Kubernetes로 개발서버 간단히 찍어내기
GCGC- CGCII 서버 엔진에 적용된 기술 (1)
[COSCUP 2022] 讓黑畫面再次偉大 - 用 PHP 寫 CLI 工具
[IGC 2017] 아마존 구승모 - 게임 엔진으로 서버 제작 및 운영까지
스마트폰 온라인 게임에서 고려해야 할 것들
DeathNote of Microsoft Windows Kernel
시작하자 단위테스트
Ndc14 분산 서버 구축의 ABC
Tuning Speculative Retries to Fight Latency (Michael Figuiere, Minh Do, Netfl...
Postman Collection Format v2.0 (pre-draft)
Ad

Similar to Swoole Love PHP (20)

PDF
Swoole Overview
PPTX
How to Supercharge your PHP Web API
PDF
"Swoole: double troubles in c", Alexandr Vronskiy
PDF
How Swoole Blows Up your Mind about PHP?
PPTX
20151229 wnmp & phalcon micro app - part I
PPSX
webservers
PDF
Laravel Poznań Meetup #12 - "Speed up web API with Laravel and Swoole using ...
PDF
Speed up web API with Laravel and Swoole using Docker
PDF
Web servers presentacion
PPTX
Nginx [engine x] and you (and WordPress)
PDF
2021.laravelconf.tw.slides1
PPTX
PHP conference Berlin 2015: running PHP on Nginx
PDF
Php through the eyes of a hoster confoo
PDF
Nginx pres
PDF
ApacheConNA 2015: What's new in Apache httpd 2.4
PDF
A look at FastCgi & Mod_PHP architecture
PPTX
Php internal architecture
PDF
PPTX
PHP from soup to nuts Course Deck
PDF
Running PHP on Nginx
Swoole Overview
How to Supercharge your PHP Web API
"Swoole: double troubles in c", Alexandr Vronskiy
How Swoole Blows Up your Mind about PHP?
20151229 wnmp & phalcon micro app - part I
webservers
Laravel Poznań Meetup #12 - "Speed up web API with Laravel and Swoole using ...
Speed up web API with Laravel and Swoole using Docker
Web servers presentacion
Nginx [engine x] and you (and WordPress)
2021.laravelconf.tw.slides1
PHP conference Berlin 2015: running PHP on Nginx
Php through the eyes of a hoster confoo
Nginx pres
ApacheConNA 2015: What's new in Apache httpd 2.4
A look at FastCgi & Mod_PHP architecture
Php internal architecture
PHP from soup to nuts Course Deck
Running PHP on Nginx
Ad

More from Yi-Feng Tzeng (20)

PDF
重新想像:如何做技術選型決策 / Rethinking : Technical Decision
PDF
擁抱開源:企業應如何善用開源技術,才能得其利而防其弊-加強版
PDF
Testing in Production, Deploy on Fridays
PDF
COSCUP 2020 Day 2 - Opening Keynote
PDF
COSCUP 2020 Day 1 - Opening Keynote
PDF
Severless PHP Case : Agile Dashboard via GitLab Board API
PDF
給資安工程師開源授權觀念
PDF
Progressive Deployment & NoDeploy
PDF
Dev(Sec)Ops - Architecture for Security and Compliance
PDF
擁抱開源:企業應如何善用開源技術,才能得其利而防其弊
PDF
淺談量子機器學習 - 當機器學習遇見量子計算
PDF
A Modern Web Architecture for (GDPR) Compliance
PDF
量子技術 (2018 03-31)
PDF
邏輯優化的灰色面:針對網頁應用的時序攻擊 (2018臺灣資安大會: 軟體安全論壇)
PDF
Modern Web Architecture Design Journey
PDF
善用 MySQL 及 PostgreSQL - RDBMS 的逆襲 - part1
PDF
恰如其分的 MySQL 設計技巧 [Modern Web 2016]
PDF
談 Uber 從 PostgreSQL 轉用 MySQL 的技術爭議
PDF
資料庫索引數據結構及主鍵設計(b+tree)(part 1)
PDF
軟體接案自由職業者 (Freelancer) 意想不到的風險
重新想像:如何做技術選型決策 / Rethinking : Technical Decision
擁抱開源:企業應如何善用開源技術,才能得其利而防其弊-加強版
Testing in Production, Deploy on Fridays
COSCUP 2020 Day 2 - Opening Keynote
COSCUP 2020 Day 1 - Opening Keynote
Severless PHP Case : Agile Dashboard via GitLab Board API
給資安工程師開源授權觀念
Progressive Deployment & NoDeploy
Dev(Sec)Ops - Architecture for Security and Compliance
擁抱開源:企業應如何善用開源技術,才能得其利而防其弊
淺談量子機器學習 - 當機器學習遇見量子計算
A Modern Web Architecture for (GDPR) Compliance
量子技術 (2018 03-31)
邏輯優化的灰色面:針對網頁應用的時序攻擊 (2018臺灣資安大會: 軟體安全論壇)
Modern Web Architecture Design Journey
善用 MySQL 及 PostgreSQL - RDBMS 的逆襲 - part1
恰如其分的 MySQL 設計技巧 [Modern Web 2016]
談 Uber 從 PostgreSQL 轉用 MySQL 的技術爭議
資料庫索引數據結構及主鍵設計(b+tree)(part 1)
軟體接案自由職業者 (Freelancer) 意想不到的風險

Recently uploaded (20)

PPT
3.Software Design for software engineering
PPTX
Matchmaking for JVMs: How to Pick the Perfect GC Partner
PDF
Sun and Bloombase Spitfire StoreSafe End-to-end Storage Security Solution
PDF
Microsoft Office 365 Crack Download Free
PDF
BoxLang Dynamic AWS Lambda - Japan Edition
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PDF
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
PPTX
4Seller: The All-in-One Multi-Channel E-Commerce Management Platform for Glob...
PPTX
Full-Stack Developer Courses That Actually Land You Jobs
PDF
infoteam HELLAS company profile 2025 presentation
PPTX
Presentation by Samna Perveen And Subhan Afzal.pptx
PPTX
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
PDF
What Makes a Great Data Visualization Consulting Service.pdf
PDF
MiniTool Power Data Recovery 12.6 Crack + Portable (Latest Version 2025)
PPTX
hospital managemt ,san.dckldnklcdnkdnkdnjadnjdjn
PPTX
ROI Analysis for Newspaper Industry with Odoo ERP
PDF
Guide to Food Delivery App Development.pdf
PPTX
Python is a high-level, interpreted programming language
PPTX
Bandicam Screen Recorder 8.2.1 Build 2529 Crack
PPTX
Download Adobe Photoshop Crack 2025 Free
3.Software Design for software engineering
Matchmaking for JVMs: How to Pick the Perfect GC Partner
Sun and Bloombase Spitfire StoreSafe End-to-end Storage Security Solution
Microsoft Office 365 Crack Download Free
BoxLang Dynamic AWS Lambda - Japan Edition
CCleaner 6.39.11548 Crack 2025 License Key
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
4Seller: The All-in-One Multi-Channel E-Commerce Management Platform for Glob...
Full-Stack Developer Courses That Actually Land You Jobs
infoteam HELLAS company profile 2025 presentation
Presentation by Samna Perveen And Subhan Afzal.pptx
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
What Makes a Great Data Visualization Consulting Service.pdf
MiniTool Power Data Recovery 12.6 Crack + Portable (Latest Version 2025)
hospital managemt ,san.dckldnklcdnkdnkdnjadnjdjn
ROI Analysis for Newspaper Industry with Odoo ERP
Guide to Food Delivery App Development.pdf
Python is a high-level, interpreted programming language
Bandicam Screen Recorder 8.2.1 Build 2529 Crack
Download Adobe Photoshop Crack 2025 Free

Swoole Love PHP