SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
ReactPHP + Symfony = PROFIT
aneb 1000req/s s minimálními nároky na server
1. sraz přátel Symfony v Praze (29.10.2015)
O mně
• Kouzelná Almara
• Skrz.cz
• @jakubkulhan
• jakub.kulhan@gmail.com
• github.com/jakubkulhan
Slovníček
• klik = najedu myší na nabídku a zmáčknu tlačítko
• imprese = podíval jsem se na nabídku

(alespoň polovina nabídky byla ve viewportu
alespoň jednu sekundu)
• CTR (click-through rate) = kliky / imprese
ReactPHP
(neplést s ReactJS!)
http://reactphp.org/
(https://github.com/jakubkulhan/hit-server-bench)
ReactPHP: req, res → λ
Symfony: req → λ → res
❓
req → λ → promise[res]
❗
github.com/jakubkulhan/
reactphp-symfony
Boot
$kernel = new AppKernel(
$environment = $input->getOption("environment"),
$environment !== "prod"
);
$kernel->boot();
$loop = Factory::create();
/** @var Container $container */
$container = $kernel->getContainer();
$container->set("react.loop", $loop);
$socket = new Socket($loop);
$http = new Server($socket);
$http->on("request", function (
Request $request,
Response $response
) use ($kernel, $loop) {
// ...
});
$socket->listen(
$port = $input->getOption("port"),
$host = $input->getOption("host")
);
echo "Listening to {$host}:{$port}n";
$loop->run();
ReactPHP → Symfony
$headers = $request->getHeaders();
$cookies = [];
if (isset($headers["Cookie"])) {
foreach ((array)$headers["Cookie"] as $cookieHeader) {
foreach (explode(";", $cookieHeader) as $cookie) {
list($name, $value) = explode("=", trim($cookie), 2);
$cookies[$name] = urldecode($value);
}
}
}
$symfonyRequest = new SymfonyRequest(
$request->getQuery(),
[], // TODO: handle post data
[],
$cookies,
[],
[
"REQUEST_URI" => $request->getPath(),
"SERVER_NAME" => explode(":", $headers["Host"])[0],
"REMOTE_ADDR" => $request->remoteAddress,
"QUERY_STRING" => http_build_query($request->getQuery()),
],
null // TODO: handle post data
);
$symfonyRequest->headers->replace($headers);
$symfonyResponse = $kernel->handle($symfonyRequest);
if ($kernel instanceof TerminableInterface) {
$kernel->terminate($symfonyRequest, $symfonyResponse);
}
Symfony → ReactPHP
if ($symfonyResponse instanceof PromiseInterface) {
$symfonyResponse->then(function (SymfonyResponse $symfonyResponse) use ($response) {
$this->send($response, $symfonyResponse);
}, function ($error) use ($loop, $response) {
echo "Exception: ", (string) $error, "n";
$response->writeHead(500, ["Content-Type" => "text/plain"]);
$response->end("500 Internal Server Error");
$loop->stop();
});
} elseif ($symfonyResponse instanceof SymfonyResponse) {
$this->send($response, $symfonyResponse);
} else {
echo "Unsupported response type: ", get_class($symfonyResponse), "n";
$response->writeHead(500, ["Content-Type" => "text/plain"]);
$response->end("500 Internal Server Error");
$loop->stop();
}
Symfony → ReactPHP (2)
private function send(Response $res, SymfonyResponse $symfonyResponse)
{
$headers = $symfonyResponse->headers->allPreserveCase();
$headers["X-Powered-By"] = "Love";
$cookies = $symfonyResponse->headers->getCookies();
if (count($cookies)) {
$headers["Set-Cookie"] = [];
foreach ($symfonyResponse->headers->getCookies() as $cookie) {
$headers["Set-Cookie"][] = (string)$cookie;
}
}
$res->writeHead($symfonyResponse->getStatusCode(), $headers);
$res->end($symfonyResponse->getContent());
}
Controller
/**
* @Controller
*/
class IndexController
{
/**
* @var LoopInterface
*
* @Autowired
*/
public $loop;
public function indexAction(Request $request)
{
return Response::create("Hello, world!n");
}
public function promiseAction(Request $request)
{
$secs = intval($request->attributes->get("secs"));
$deferred = new Deferred();
$this->loop->addTimer($secs, function () use ($secs, $deferred) {
$deferred->resolve(Response::create("{$secs} seconds later...n"));
});
return $deferred->promise();
}
}
Knihovny
• ReactPHP (např. HTTP klient, ZeroMQ)

https://github.com/reactphp
• MySQL

https://github.com/kaja47/async-mysql

https://github.com/KhristenkoYura/react-mysql

https://github.com/bixuehujin/reactphp-mysql
• Redis

https://github.com/nrk/predis-async
• RabbitMQ

https://github.com/jakubkulhan/bunny
Díky!
Otázky?

Weitere ähnliche Inhalte

Was ist angesagt?

Trading with opensource tools, two years later
Trading with opensource tools, two years laterTrading with opensource tools, two years later
Trading with opensource tools, two years later
clkao
 
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用用Tornado开发RESTful API运用
用Tornado开发RESTful API运用
Felinx Lee
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
clkao
 

Was ist angesagt? (20)

Functional php
Functional phpFunctional php
Functional php
 
KubeCon EU 2016: Custom Volume Plugins
KubeCon EU 2016: Custom Volume PluginsKubeCon EU 2016: Custom Volume Plugins
KubeCon EU 2016: Custom Volume Plugins
 
Git avançado
Git avançadoGit avançado
Git avançado
 
Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generators
 
node ffi
node ffinode ffi
node ffi
 
Trading with opensource tools, two years later
Trading with opensource tools, two years laterTrading with opensource tools, two years later
Trading with opensource tools, two years later
 
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 Version
 
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用用Tornado开发RESTful API运用
用Tornado开发RESTful API运用
 
Python Coroutines, Present and Future
Python Coroutines, Present and FuturePython Coroutines, Present and Future
Python Coroutines, Present and Future
 
dotCloud and go
dotCloud and godotCloud and go
dotCloud and go
 
Call stack, event loop and async programming
Call stack, event loop and async programmingCall stack, event loop and async programming
Call stack, event loop and async programming
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
 
Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話
 
ES6 generators
ES6 generatorsES6 generators
ES6 generators
 
Txjs
TxjsTxjs
Txjs
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
 
Consuming Web Services with Swift and Rx
Consuming Web Services with Swift and RxConsuming Web Services with Swift and Rx
Consuming Web Services with Swift and Rx
 

Andere mochten auch

Planificador de proyectos plantilla
Planificador de proyectos plantillaPlanificador de proyectos plantilla
Planificador de proyectos plantilla
Oscar Ortiz
 
Section a media theories
Section a   media theoriesSection a   media theories
Section a media theories
Liamcwhite
 
The dynamics of knowledge creation: academics' changing writing practices – i...
The dynamics of knowledge creation: academics' changing writing practices – i...The dynamics of knowledge creation: academics' changing writing practices – i...
The dynamics of knowledge creation: academics' changing writing practices – i...
Queen's University Belfast
 
Txns_iPhone_Working_Splits
Txns_iPhone_Working_SplitsTxns_iPhone_Working_Splits
Txns_iPhone_Working_Splits
Luke Eastman
 

Andere mochten auch (20)

Depre.jodo
Depre.jodoDepre.jodo
Depre.jodo
 
Digital studieteknikk Dyrløkkeåsen skole 2016
Digital studieteknikk Dyrløkkeåsen skole 2016Digital studieteknikk Dyrløkkeåsen skole 2016
Digital studieteknikk Dyrløkkeåsen skole 2016
 
Biodiversity Heritage Library - an overview for the Australian Museum
Biodiversity Heritage Library - an overview for the Australian MuseumBiodiversity Heritage Library - an overview for the Australian Museum
Biodiversity Heritage Library - an overview for the Australian Museum
 
Planificador de proyectos plantilla
Planificador de proyectos plantillaPlanificador de proyectos plantilla
Planificador de proyectos plantilla
 
Lectura 03
Lectura 03Lectura 03
Lectura 03
 
Section a media theories
Section a   media theoriesSection a   media theories
Section a media theories
 
Martin Zeman - Moje první aplikace v Symfony 3 (4. sraz přátel Symfony v Praze)
Martin Zeman - Moje první aplikace v Symfony 3 (4. sraz přátel Symfony v Praze)Martin Zeman - Moje první aplikace v Symfony 3 (4. sraz přátel Symfony v Praze)
Martin Zeman - Moje první aplikace v Symfony 3 (4. sraz přátel Symfony v Praze)
 
The Largest E-Cig Company for Smok Ultra Mod
The Largest E-Cig Company for Smok Ultra ModThe Largest E-Cig Company for Smok Ultra Mod
The Largest E-Cig Company for Smok Ultra Mod
 
Tomáš Fejfar - Elk - Víc než jen logy (4. sraz přátel Symfony v Praze)
Tomáš Fejfar - Elk - Víc než jen logy (4. sraz přátel Symfony v Praze)Tomáš Fejfar - Elk - Víc než jen logy (4. sraz přátel Symfony v Praze)
Tomáš Fejfar - Elk - Víc než jen logy (4. sraz přátel Symfony v Praze)
 
Conteo
ConteoConteo
Conteo
 
2 taller civil[1]
2 taller civil[1]2 taller civil[1]
2 taller civil[1]
 
Хитрые таргетинги для коммерческих спецпроектов
Хитрые таргетинги для коммерческих спецпроектовХитрые таргетинги для коммерческих спецпроектов
Хитрые таргетинги для коммерческих спецпроектов
 
Plan de gestión del conocimiento
Plan de gestión del conocimientoPlan de gestión del conocimiento
Plan de gestión del conocimiento
 
The dynamics of knowledge creation: academics' changing writing practices – i...
The dynamics of knowledge creation: academics' changing writing practices – i...The dynamics of knowledge creation: academics' changing writing practices – i...
The dynamics of knowledge creation: academics' changing writing practices – i...
 
c'est FACILE ! se nourrir avec les lois de la diététique chinoise...
c'est FACILE ! se nourrir avec les lois de la diététique chinoise...c'est FACILE ! se nourrir avec les lois de la diététique chinoise...
c'est FACILE ! se nourrir avec les lois de la diététique chinoise...
 
Lectura 2 qué es ser persona para el derecho
Lectura 2 qué es ser persona para el derechoLectura 2 qué es ser persona para el derecho
Lectura 2 qué es ser persona para el derecho
 
Txns_iPhone_Working_Splits
Txns_iPhone_Working_SplitsTxns_iPhone_Working_Splits
Txns_iPhone_Working_Splits
 
Garage storage solutions in fort worth tx
Garage storage solutions in fort worth txGarage storage solutions in fort worth tx
Garage storage solutions in fort worth tx
 
Tomáš Strejček - Velikost týmu vs. monolith a mikroservicy (11. sraz přátel ...
Tomáš Strejček - Velikost týmu vs. monolith a mikroservicy  (11. sraz přátel ...Tomáš Strejček - Velikost týmu vs. monolith a mikroservicy  (11. sraz přátel ...
Tomáš Strejček - Velikost týmu vs. monolith a mikroservicy (11. sraz přátel ...
 
Plan de gestión del conocimiento
Plan de gestión del conocimientoPlan de gestión del conocimiento
Plan de gestión del conocimiento
 

Ähnlich wie Jakub Kulhán - ReactPHP + Symfony = PROFIT (1. sraz přátel Symfony v Praze)

Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)
Fabien Potencier
 
The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)
Fabien Potencier
 
Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)
Fabien Potencier
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門
lestrrat
 
優しいWAFの作り方
優しいWAFの作り方優しいWAFの作り方
優しいWAFの作り方
techmemo
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
patter
 

Ähnlich wie Jakub Kulhán - ReactPHP + Symfony = PROFIT (1. sraz přátel Symfony v Praze) (20)

Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous php
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous php
 
Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12
 
When symfony met promises
When symfony met promises When symfony met promises
When symfony met promises
 
The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)
 
Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challenger
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 
Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)
 
Tobias Nyholm "Deep dive into Symfony 4 internals"
Tobias Nyholm "Deep dive into Symfony 4 internals"Tobias Nyholm "Deep dive into Symfony 4 internals"
Tobias Nyholm "Deep dive into Symfony 4 internals"
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 
How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Plack - LPW 2009
Plack - LPW 2009Plack - LPW 2009
Plack - LPW 2009
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
優しいWAFの作り方
優しいWAFの作り方優しいWAFの作り方
優しいWAFの作り方
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 

Mehr von Péhápkaři

Mehr von Péhápkaři (20)

Startup vs korporace vs Previo
Startup vs korporace vs PrevioStartup vs korporace vs Previo
Startup vs korporace vs Previo
 
RabbitMQ a ElasticSearch v Previu
RabbitMQ a ElasticSearch v PreviuRabbitMQ a ElasticSearch v Previu
RabbitMQ a ElasticSearch v Previu
 
Martin Froněk - Jak využít soft skills ve svůj prospěch 2 (15. sraz přátel PH...
Martin Froněk - Jak využít soft skills ve svůj prospěch 2 (15. sraz přátel PH...Martin Froněk - Jak využít soft skills ve svůj prospěch 2 (15. sraz přátel PH...
Martin Froněk - Jak využít soft skills ve svůj prospěch 2 (15. sraz přátel PH...
 
Čtvrtkon #53 - Štěpán Zikmund
Čtvrtkon #53 - Štěpán ZikmundČtvrtkon #53 - Štěpán Zikmund
Čtvrtkon #53 - Štěpán Zikmund
 
Václav Makeš - Infrastructure as code - Jak nahazovat stroje a nic moc nevědě...
Václav Makeš - Infrastructure as code - Jak nahazovat stroje a nic moc nevědě...Václav Makeš - Infrastructure as code - Jak nahazovat stroje a nic moc nevědě...
Václav Makeš - Infrastructure as code - Jak nahazovat stroje a nic moc nevědě...
 
Tomáš Klíma - Implementace BitCoinut v praxi (13. sraz přátel PHP v Praze)
Tomáš Klíma - Implementace BitCoinut v praxi (13. sraz přátel PHP v Praze)Tomáš Klíma - Implementace BitCoinut v praxi (13. sraz přátel PHP v Praze)
Tomáš Klíma - Implementace BitCoinut v praxi (13. sraz přátel PHP v Praze)
 
PHP Evening #1 - Automatizace [Jan Klat]
PHP Evening #1 - Automatizace [Jan Klat]PHP Evening #1 - Automatizace [Jan Klat]
PHP Evening #1 - Automatizace [Jan Klat]
 
PHP Evening #1 - Propel ORM [Martin Sojka]
PHP Evening #1 - Propel ORM [Martin Sojka]PHP Evening #1 - Propel ORM [Martin Sojka]
PHP Evening #1 - Propel ORM [Martin Sojka]
 
Tomáš Kazatel - Jsme přece vývojáři, ne textaři (12. sraz přátel PHP v P...
Tomáš Kazatel - Jsme přece vývojáři, ne textaři (12. sraz přátel PHP v P...Tomáš Kazatel - Jsme přece vývojáři, ne textaři (12. sraz přátel PHP v P...
Tomáš Kazatel - Jsme přece vývojáři, ne textaři (12. sraz přátel PHP v P...
 
Jakub Kratina - Když si dva vývojáři založí s.r.o. (12. sraz přátel PHP v Pra...
Jakub Kratina - Když si dva vývojáři založí s.r.o. (12. sraz přátel PHP v Pra...Jakub Kratina - Když si dva vývojáři založí s.r.o. (12. sraz přátel PHP v Pra...
Jakub Kratina - Když si dva vývojáři založí s.r.o. (12. sraz přátel PHP v Pra...
 
Petr Pavel - Co musí programátor umět kromě programování (12. sraz přátel PHP...
Petr Pavel - Co musí programátor umět kromě programování (12. sraz přátel PHP...Petr Pavel - Co musí programátor umět kromě programování (12. sraz přátel PHP...
Petr Pavel - Co musí programátor umět kromě programování (12. sraz přátel PHP...
 
Jindřich Kubát - Microservice – Post Monolith Architecture (11. sraz přátel P...
Jindřich Kubát - Microservice – Post Monolith Architecture (11. sraz přátel P...Jindřich Kubát - Microservice – Post Monolith Architecture (11. sraz přátel P...
Jindřich Kubát - Microservice – Post Monolith Architecture (11. sraz přátel P...
 
Jakub Kratina - Jak testovat aplikace s radostí díky Codeception (11. sraz př...
Jakub Kratina - Jak testovat aplikace s radostí díky Codeception (11. sraz př...Jakub Kratina - Jak testovat aplikace s radostí díky Codeception (11. sraz př...
Jakub Kratina - Jak testovat aplikace s radostí díky Codeception (11. sraz př...
 
Ako nespáliť server - Monit [Jozef Lami] (7. sraz, Praha)
Ako nespáliť server - Monit [Jozef Lami] (7. sraz, Praha)Ako nespáliť server - Monit [Jozef Lami] (7. sraz, Praha)
Ako nespáliť server - Monit [Jozef Lami] (7. sraz, Praha)
 
Doctrine - Co dělat když entity nestačí [Filip Procházka] (7. sraz, Praha)
Doctrine - Co dělat když entity nestačí [Filip Procházka] (7. sraz, Praha)Doctrine - Co dělat když entity nestačí [Filip Procházka] (7. sraz, Praha)
Doctrine - Co dělat když entity nestačí [Filip Procházka] (7. sraz, Praha)
 
Blackfire.io - Fire up your php app performance [Jan Kopp] (7. sraz, Praha)
Blackfire.io - Fire up your php app performance [Jan Kopp] (7. sraz, Praha)Blackfire.io - Fire up your php app performance [Jan Kopp] (7. sraz, Praha)
Blackfire.io - Fire up your php app performance [Jan Kopp] (7. sraz, Praha)
 
Automatizace jednoduše [Martin Zeman] (6. sraz, Praha, 31.3.2016)
Automatizace jednoduše [Martin Zeman] (6. sraz, Praha, 31.3.2016)Automatizace jednoduše [Martin Zeman] (6. sraz, Praha, 31.3.2016)
Automatizace jednoduše [Martin Zeman] (6. sraz, Praha, 31.3.2016)
 
MicroKernel aneb spatny nazev pro Helper (5. sraz pratel Symfony)
MicroKernel aneb spatny nazev pro Helper (5. sraz pratel Symfony)MicroKernel aneb spatny nazev pro Helper (5. sraz pratel Symfony)
MicroKernel aneb spatny nazev pro Helper (5. sraz pratel Symfony)
 
Petr Nikolas Prokop - Symfony framework (0. sraz přátel Symfony v Hradci Král...
Petr Nikolas Prokop - Symfony framework (0. sraz přátel Symfony v Hradci Král...Petr Nikolas Prokop - Symfony framework (0. sraz přátel Symfony v Hradci Král...
Petr Nikolas Prokop - Symfony framework (0. sraz přátel Symfony v Hradci Král...
 
Karel Škopek - WordPress + Laravel = <3 (4. sraz přátel Symfony v Praze)
Karel Škopek - WordPress + Laravel = <3 (4. sraz přátel Symfony v Praze)Karel Škopek - WordPress + Laravel = <3 (4. sraz přátel Symfony v Praze)
Karel Škopek - WordPress + Laravel = <3 (4. sraz přátel Symfony v Praze)
 

Kürzlich hochgeladen

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Kürzlich hochgeladen (20)

Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 

Jakub Kulhán - ReactPHP + Symfony = PROFIT (1. sraz přátel Symfony v Praze)

  • 1. ReactPHP + Symfony = PROFIT aneb 1000req/s s minimálními nároky na server 1. sraz přátel Symfony v Praze (29.10.2015)
  • 2. O mně • Kouzelná Almara • Skrz.cz • @jakubkulhan • jakub.kulhan@gmail.com • github.com/jakubkulhan
  • 3. Slovníček • klik = najedu myší na nabídku a zmáčknu tlačítko • imprese = podíval jsem se na nabídku
 (alespoň polovina nabídky byla ve viewportu alespoň jednu sekundu) • CTR (click-through rate) = kliky / imprese
  • 4.
  • 5.
  • 7. ReactPHP: req, res → λ Symfony: req → λ → res ❓
  • 8. req → λ → promise[res] ❗
  • 10. Boot $kernel = new AppKernel( $environment = $input->getOption("environment"), $environment !== "prod" ); $kernel->boot(); $loop = Factory::create(); /** @var Container $container */ $container = $kernel->getContainer(); $container->set("react.loop", $loop); $socket = new Socket($loop); $http = new Server($socket); $http->on("request", function ( Request $request, Response $response ) use ($kernel, $loop) { // ... }); $socket->listen( $port = $input->getOption("port"), $host = $input->getOption("host") ); echo "Listening to {$host}:{$port}n"; $loop->run();
  • 11. ReactPHP → Symfony $headers = $request->getHeaders(); $cookies = []; if (isset($headers["Cookie"])) { foreach ((array)$headers["Cookie"] as $cookieHeader) { foreach (explode(";", $cookieHeader) as $cookie) { list($name, $value) = explode("=", trim($cookie), 2); $cookies[$name] = urldecode($value); } } } $symfonyRequest = new SymfonyRequest( $request->getQuery(), [], // TODO: handle post data [], $cookies, [], [ "REQUEST_URI" => $request->getPath(), "SERVER_NAME" => explode(":", $headers["Host"])[0], "REMOTE_ADDR" => $request->remoteAddress, "QUERY_STRING" => http_build_query($request->getQuery()), ], null // TODO: handle post data ); $symfonyRequest->headers->replace($headers); $symfonyResponse = $kernel->handle($symfonyRequest); if ($kernel instanceof TerminableInterface) { $kernel->terminate($symfonyRequest, $symfonyResponse); }
  • 12. Symfony → ReactPHP if ($symfonyResponse instanceof PromiseInterface) { $symfonyResponse->then(function (SymfonyResponse $symfonyResponse) use ($response) { $this->send($response, $symfonyResponse); }, function ($error) use ($loop, $response) { echo "Exception: ", (string) $error, "n"; $response->writeHead(500, ["Content-Type" => "text/plain"]); $response->end("500 Internal Server Error"); $loop->stop(); }); } elseif ($symfonyResponse instanceof SymfonyResponse) { $this->send($response, $symfonyResponse); } else { echo "Unsupported response type: ", get_class($symfonyResponse), "n"; $response->writeHead(500, ["Content-Type" => "text/plain"]); $response->end("500 Internal Server Error"); $loop->stop(); }
  • 13. Symfony → ReactPHP (2) private function send(Response $res, SymfonyResponse $symfonyResponse) { $headers = $symfonyResponse->headers->allPreserveCase(); $headers["X-Powered-By"] = "Love"; $cookies = $symfonyResponse->headers->getCookies(); if (count($cookies)) { $headers["Set-Cookie"] = []; foreach ($symfonyResponse->headers->getCookies() as $cookie) { $headers["Set-Cookie"][] = (string)$cookie; } } $res->writeHead($symfonyResponse->getStatusCode(), $headers); $res->end($symfonyResponse->getContent()); }
  • 14. Controller /** * @Controller */ class IndexController { /** * @var LoopInterface * * @Autowired */ public $loop; public function indexAction(Request $request) { return Response::create("Hello, world!n"); } public function promiseAction(Request $request) { $secs = intval($request->attributes->get("secs")); $deferred = new Deferred(); $this->loop->addTimer($secs, function () use ($secs, $deferred) { $deferred->resolve(Response::create("{$secs} seconds later...n")); }); return $deferred->promise(); } }
  • 15. Knihovny • ReactPHP (např. HTTP klient, ZeroMQ)
 https://github.com/reactphp • MySQL
 https://github.com/kaja47/async-mysql
 https://github.com/KhristenkoYura/react-mysql
 https://github.com/bixuehujin/reactphp-mysql • Redis
 https://github.com/nrk/predis-async • RabbitMQ
 https://github.com/jakubkulhan/bunny