SlideShare une entreprise Scribd logo
1  sur  20
Télécharger pour lire hors ligne
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 1/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
SPEEDUPWEBAPISWITHSPEEDUPWEBAPISWITH
EXPRESSIVEEXPRESSIVEANDANDSWOOLESWOOLE
by
Senior Software Engineer
(USA)
, Verona (Italy), 12th May
Enrico Zimuel
Rogue Wave Software
phpDay 2018
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 2/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
ABOUTMEABOUTME
Developer since 1996
Senior Software Engineer at
Inc.
Core team of ,
and
and international speaker
Research Programmer at
Co-founder of (Italy)
Rogue Wave Software
Apigility
Expressive Zend Framework
TEDx
Amsterdam University
PUG Torino
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 3/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
EXPRESSIVEEXPRESSIVE
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 4/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
The PHP framework for middleware applications
PSR-7 support (using )
PSR-15 support
Piping work ow (using )
Features: routing, dependency injection, templating,
error handling
Last release 3.0.6, 16th April 2018
zend-diactoros
zend-stratigility
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 5/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
ABASICWEBAPIABASICWEBAPI
use ZendDiactorosResponseJsonResponse;
use ZendExpressiveApplication;
$container = require 'config/container.php';
$app = $container->get(Application::class);
$app->pipe('/api/ping', function($request) {
return new JsonResponse(['ack' => time()]);
});
// or $app->pipe('/api/ping', AppHandlerPingHandler::class);
$app->run();
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 6/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
REQUESTHANDLERREQUESTHANDLER
use PsrHttpMessageResponseInterface; // PSR-7
use PsrHttpMessageServerRequestInterface; // PSR-7
use PsrHttpServerRequestHandlerInterface; // PSR-15
use ZendDiactorosResponseJsonResponse;
class PingHandler implements RequestHandlerInterface
{
public function handle(
ServerRequestInterface $request
) : ResponseInterface
{
return new JsonResponse(['ack' => time()]);
}
}
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 7/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
MIDDLEWARECLASSMIDDLEWARECLASS
use PsrHttpMessageResponseInterface; // PSR-7
use PsrHttpMessageServerRequestInterface; // PSR-7
use PsrHttpServerMiddlewareInterface; // PSR-15
use PsrHttpServerRequestHandlerInterface; // PSR-15
class AuthMiddleware implements MiddlewareInterface
{
// ...
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
) : ResponseInterface
{
$user = $this->auth->authenticate($request);
if (null !== $user) {
return $handler->handle($request->withAttribute(
UserInterface::class,
$user
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 8/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
EXAMPLE:ROUTINGRESTAPIEXAMPLE:ROUTINGRESTAPI
$app->route('/api/users[/{id}]', [
AuthenticationAuthenticationMiddleware::class,
AuthorizationAuthorizationMiddleware::class,
ApiActionUserAction::class
], ['GET', 'POST', 'PATCH', 'DELETE'], 'api.users');
// or route each HTTP method
$app->get('/api/users[/{id}]', ..., 'api.users.get');
$app->post('/api/users', ..., 'api.users.post');
$app->patch('/api/users/{id}', ..., 'api.users.patch');
$app->delete('/api/users/{id}', ..., 'api.users.delete');
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 9/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
QUICKSTARTQUICKSTART
You can start using Expressive with :composer
composer create-project zendframework/zend-expressive-skeleton <dir>
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 10/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
LIBRARIESFORAPILIBRARIESFORAPI
HAL-JSON:
Problem details:
Filtering & validation:
Authentication (HTTP Basic, OAuth2):
Authorization (ACL, RBAC):
zend-expressive-hal
zend-problem-details
zend-input lter
zend-expressive-
authentication
zend-expressive-
authorization
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 11/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
RESTEXAMPLERESTEXAMPLE
github.com/ezimuel/zend-expressive-api
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 12/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
SWOOLESWOOLE
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 13/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
Swoole is an async programming framework for PHP 7
PHP extension, install:
Released under Apache license 2.0
More info at
pecl install swoole
swoole.co.uk
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 14/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
FEATURESFEATURES
Event-driven, asynchronous programming for PHP
Async TCP / UDP / HTTP / Websocket / HTTP2
client/server side API
IPv4 / IPv6 / Unixsocket / TCP/ UDP and SSL / TLS
support
, scalable, support C1000K
Fast serializer / unserializer
Milliseconds task scheduler
High performance
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 15/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
HTTPSERVERHTTPSERVER
$http = new swoole_http_server("127.0.0.1", 9501);
$http->on("start", function ($server) {
echo "Started at http://127.0.0.1:9501n";
});
$http->on("request", function ($request, $response) {
$response->header("Content-Type", "text/plain");
$response->end("Hello Worldn");
});
$http->start();
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 16/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
EXPRESSIVEWITHSWOOLEEXPRESSIVEWITHSWOOLE
Use library
Install:
Usage:
wshafer/swoole-expressive
composer require wshafer/swoole-expressive:dev-master
vendor/bin/swoole-expressive --host=0.0.0.0 --port=8080
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 17/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
HTTPSERVERFORPSR-7HTTPSERVERFORPSR-7
use SwooleHttpRequest;
use SwooleHttpResponse
$http = new swoole_http_server($host, $port);
$http->on(
'request',
function (Request $request, Response $response) use
($app, $psr7Request, $swooleResponse) {
$psrResponse = $app->handle($psr7Request->from($request));
$swooleResponse->fromPsr7($psrResponse, $response);
}
);
$http->start();
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 18/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
SWOOLEVS.NGINXVS.APACHESWOOLEVS.NGINXVS.APACHE
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 19/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
BENCHMARKRESULTSBENCHMARKRESULTS
Expressive with Swoole runs 4x faster than nginx and
Apache ( )source
5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018
https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 20/20
© 2018 Rogue Wave Software, Inc. All Rights Reserved.
THANKS!THANKS!
Rate this talk at
This work is licensed under a
.
I used to make this presentation.
joind.in/talk/bef90
Creative Commons Attribution-ShareAlike 3.0 Unported License
reveal.js

Contenu connexe

Tendances

Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparison
Hiroshi Nakamura
 
PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2
Graham Dumpleton
 
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
 
How to deploy node to production
How to deploy node to productionHow to deploy node to production
How to deploy node to production
Sean Hess
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Tom Croucher
 
Assurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring frameworkAssurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring framework
Gosuke Miyashita
 

Tendances (20)

Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 
Plack at OSCON 2010
Plack at OSCON 2010Plack at OSCON 2010
Plack at OSCON 2010
 
Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014
 
Introduction to Flask Micro Framework
Introduction to Flask Micro FrameworkIntroduction to Flask Micro Framework
Introduction to Flask Micro Framework
 
Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparison
 
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
 
PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2PyCon US 2012 - State of WSGI 2
PyCon US 2012 - State of WSGI 2
 
Automated infrastructure is on the menu
Automated infrastructure is on the menuAutomated infrastructure is on the menu
Automated infrastructure is on the menu
 
Continuous testing In PHP
Continuous testing In PHPContinuous testing In PHP
Continuous testing In PHP
 
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
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stack
 
How to deploy node to production
How to deploy node to productionHow to deploy node to production
How to deploy node to production
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Using Node.js to  Build Great  Streaming Services - HTML5 Dev ConfUsing Node.js to  Build Great  Streaming Services - HTML5 Dev Conf
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Commencer avec le TDD
Commencer avec le TDDCommencer avec le TDD
Commencer avec le TDD
 
Testing your infrastructure with litmus
Testing your infrastructure with litmusTesting your infrastructure with litmus
Testing your infrastructure with litmus
 
Infrastructure as code - Python Saati #36
Infrastructure as code - Python Saati #36Infrastructure as code - Python Saati #36
Infrastructure as code - Python Saati #36
 
Assurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring frameworkAssurer - a pluggable server testing/monitoring framework
Assurer - a pluggable server testing/monitoring framework
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 

Similaire à Speed up web APIs with Expressive and Swoole (PHP Day 2018)

Similaire à Speed up web APIs with Expressive and Swoole (PHP Day 2018) (20)

Develop microservices in php
Develop microservices in phpDevelop microservices in php
Develop microservices in php
 
Building web APIs in PHP with Zend Expressive
Building web APIs in PHP with Zend ExpressiveBuilding web APIs in PHP with Zend Expressive
Building web APIs in PHP with Zend Expressive
 
Develop web APIs in PHP using middleware with Expressive (Code Europe)
Develop web APIs in PHP using middleware with Expressive (Code Europe)Develop web APIs in PHP using middleware with Expressive (Code Europe)
Develop web APIs in PHP using middleware with Expressive (Code Europe)
 
Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
 
Developing web APIs using middleware in PHP 7
Developing web APIs using middleware in PHP 7Developing web APIs using middleware in PHP 7
Developing web APIs using middleware in PHP 7
 
Flutter for web
Flutter for webFlutter for web
Flutter for web
 
Building Effective Apache Geode Applications with Spring Data GemFire
Building Effective Apache Geode Applications with Spring Data GemFireBuilding Effective Apache Geode Applications with Spring Data GemFire
Building Effective Apache Geode Applications with Spring Data GemFire
 
Don't worry be API with Slim framework and Joomla
Don't worry be API with Slim framework and JoomlaDon't worry be API with Slim framework and Joomla
Don't worry be API with Slim framework and Joomla
 
Understanding and Developing Web Services - For DBAs and Developers
Understanding and Developing Web Services - For DBAs and DevelopersUnderstanding and Developing Web Services - For DBAs and Developers
Understanding and Developing Web Services - For DBAs and Developers
 
Building and managing applications fast for IBM i
Building and managing applications fast for IBM iBuilding and managing applications fast for IBM i
Building and managing applications fast for IBM i
 
From Open Source to Open API with Restlet
From Open Source to Open API with RestletFrom Open Source to Open API with Restlet
From Open Source to Open API with Restlet
 
Timings API: Performance Assertion during the functional testing
 Timings API: Performance Assertion during the functional testing Timings API: Performance Assertion during the functional testing
Timings API: Performance Assertion during the functional testing
 
Mashups
MashupsMashups
Mashups
 
Node.js Workshop
Node.js WorkshopNode.js Workshop
Node.js Workshop
 
Building Rich Applications with Appcelerator
Building Rich Applications with AppceleratorBuilding Rich Applications with Appcelerator
Building Rich Applications with Appcelerator
 
Owasp top 10 web application security hazards part 2
Owasp top 10 web application security hazards part 2Owasp top 10 web application security hazards part 2
Owasp top 10 web application security hazards part 2
 
WP REST API - Building a simple Web Application
WP REST API - Building a simple Web ApplicationWP REST API - Building a simple Web Application
WP REST API - Building a simple Web Application
 
Developing Web Services from Scratch - For DBAs and Database Developers
Developing Web Services from Scratch - For DBAs and Database DevelopersDeveloping Web Services from Scratch - For DBAs and Database Developers
Developing Web Services from Scratch - For DBAs and Database Developers
 
InspiringCon14: ElePHPants on speed: Running TYPO3 Flow on HipHop VM
InspiringCon14: ElePHPants on speed: Running TYPO3 Flow on HipHop VMInspiringCon14: ElePHPants on speed: Running TYPO3 Flow on HipHop VM
InspiringCon14: ElePHPants on speed: Running TYPO3 Flow on HipHop VM
 
An Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP ProgrammersAn Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP Programmers
 

Plus de Zend by Rogue Wave Software

Plus de Zend by Rogue Wave Software (20)

Speed and security for your PHP application
Speed and security for your PHP applicationSpeed and security for your PHP application
Speed and security for your PHP application
 
To PHP 7 and beyond
To PHP 7 and beyondTo PHP 7 and beyond
To PHP 7 and beyond
 
The Sodium crypto library of PHP 7.2 (PHP Day 2018)
The Sodium crypto library of PHP 7.2 (PHP Day 2018)The Sodium crypto library of PHP 7.2 (PHP Day 2018)
The Sodium crypto library of PHP 7.2 (PHP Day 2018)
 
Middleware web APIs in PHP 7.x
Middleware web APIs in PHP 7.xMiddleware web APIs in PHP 7.x
Middleware web APIs in PHP 7.x
 
Ongoing management of your PHP 7 application
Ongoing management of your PHP 7 applicationOngoing management of your PHP 7 application
Ongoing management of your PHP 7 application
 
The Docker development template for PHP
The Docker development template for PHPThe Docker development template for PHP
The Docker development template for PHP
 
The most exciting features of PHP 7.1
The most exciting features of PHP 7.1The most exciting features of PHP 7.1
The most exciting features of PHP 7.1
 
Unit testing for project managers
Unit testing for project managersUnit testing for project managers
Unit testing for project managers
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
Deploying PHP apps on the cloud
Deploying PHP apps on the cloudDeploying PHP apps on the cloud
Deploying PHP apps on the cloud
 
Data is dead. Long live data!
Data is dead. Long live data! Data is dead. Long live data!
Data is dead. Long live data!
 
Optimizing performance
Optimizing performanceOptimizing performance
Optimizing performance
 
Resolving problems & high availability
Resolving problems & high availabilityResolving problems & high availability
Resolving problems & high availability
 
Developing apps faster
Developing apps fasterDeveloping apps faster
Developing apps faster
 
Keeping up with PHP
Keeping up with PHPKeeping up with PHP
Keeping up with PHP
 
Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i  Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i
 
Getting started with PHP on IBM i
Getting started with PHP on IBM iGetting started with PHP on IBM i
Getting started with PHP on IBM i
 
Continuous Delivery e-book
Continuous Delivery e-bookContinuous Delivery e-book
Continuous Delivery e-book
 
Standard CMS on standard PHP Stack - Drupal and Zend Server
Standard CMS on standard PHP Stack - Drupal and Zend ServerStandard CMS on standard PHP Stack - Drupal and Zend Server
Standard CMS on standard PHP Stack - Drupal and Zend Server
 
Dev & Prod - PHP Applications in the Cloud
Dev & Prod - PHP Applications in the CloudDev & Prod - PHP Applications in the Cloud
Dev & Prod - PHP Applications in the Cloud
 

Dernier

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+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 Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
+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
 

Dernier (20)

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
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
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%+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...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+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...
 
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
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%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
 
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...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
+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...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
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
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 

Speed up web APIs with Expressive and Swoole (PHP Day 2018)

  • 1. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 1/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. SPEEDUPWEBAPISWITHSPEEDUPWEBAPISWITH EXPRESSIVEEXPRESSIVEANDANDSWOOLESWOOLE by Senior Software Engineer (USA) , Verona (Italy), 12th May Enrico Zimuel Rogue Wave Software phpDay 2018
  • 2. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 2/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. ABOUTMEABOUTME Developer since 1996 Senior Software Engineer at Inc. Core team of , and and international speaker Research Programmer at Co-founder of (Italy) Rogue Wave Software Apigility Expressive Zend Framework TEDx Amsterdam University PUG Torino
  • 3. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 3/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. EXPRESSIVEEXPRESSIVE
  • 4. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 4/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. The PHP framework for middleware applications PSR-7 support (using ) PSR-15 support Piping work ow (using ) Features: routing, dependency injection, templating, error handling Last release 3.0.6, 16th April 2018 zend-diactoros zend-stratigility
  • 5. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 5/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. ABASICWEBAPIABASICWEBAPI use ZendDiactorosResponseJsonResponse; use ZendExpressiveApplication; $container = require 'config/container.php'; $app = $container->get(Application::class); $app->pipe('/api/ping', function($request) { return new JsonResponse(['ack' => time()]); }); // or $app->pipe('/api/ping', AppHandlerPingHandler::class); $app->run();
  • 6. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 6/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. REQUESTHANDLERREQUESTHANDLER use PsrHttpMessageResponseInterface; // PSR-7 use PsrHttpMessageServerRequestInterface; // PSR-7 use PsrHttpServerRequestHandlerInterface; // PSR-15 use ZendDiactorosResponseJsonResponse; class PingHandler implements RequestHandlerInterface { public function handle( ServerRequestInterface $request ) : ResponseInterface { return new JsonResponse(['ack' => time()]); } }
  • 7. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 7/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. MIDDLEWARECLASSMIDDLEWARECLASS use PsrHttpMessageResponseInterface; // PSR-7 use PsrHttpMessageServerRequestInterface; // PSR-7 use PsrHttpServerMiddlewareInterface; // PSR-15 use PsrHttpServerRequestHandlerInterface; // PSR-15 class AuthMiddleware implements MiddlewareInterface { // ... public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ) : ResponseInterface { $user = $this->auth->authenticate($request); if (null !== $user) { return $handler->handle($request->withAttribute( UserInterface::class, $user
  • 8. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 8/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. EXAMPLE:ROUTINGRESTAPIEXAMPLE:ROUTINGRESTAPI $app->route('/api/users[/{id}]', [ AuthenticationAuthenticationMiddleware::class, AuthorizationAuthorizationMiddleware::class, ApiActionUserAction::class ], ['GET', 'POST', 'PATCH', 'DELETE'], 'api.users'); // or route each HTTP method $app->get('/api/users[/{id}]', ..., 'api.users.get'); $app->post('/api/users', ..., 'api.users.post'); $app->patch('/api/users/{id}', ..., 'api.users.patch'); $app->delete('/api/users/{id}', ..., 'api.users.delete');
  • 9. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 9/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. QUICKSTARTQUICKSTART You can start using Expressive with :composer composer create-project zendframework/zend-expressive-skeleton <dir>
  • 10. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 10/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. LIBRARIESFORAPILIBRARIESFORAPI HAL-JSON: Problem details: Filtering & validation: Authentication (HTTP Basic, OAuth2): Authorization (ACL, RBAC): zend-expressive-hal zend-problem-details zend-input lter zend-expressive- authentication zend-expressive- authorization
  • 11. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 11/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. RESTEXAMPLERESTEXAMPLE github.com/ezimuel/zend-expressive-api
  • 12. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 12/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. SWOOLESWOOLE
  • 13. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 13/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. Swoole is an async programming framework for PHP 7 PHP extension, install: Released under Apache license 2.0 More info at pecl install swoole swoole.co.uk
  • 14. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 14/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. FEATURESFEATURES Event-driven, asynchronous programming for PHP Async TCP / UDP / HTTP / Websocket / HTTP2 client/server side API IPv4 / IPv6 / Unixsocket / TCP/ UDP and SSL / TLS support , scalable, support C1000K Fast serializer / unserializer Milliseconds task scheduler High performance
  • 15. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 15/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. HTTPSERVERHTTPSERVER $http = new swoole_http_server("127.0.0.1", 9501); $http->on("start", function ($server) { echo "Started at http://127.0.0.1:9501n"; }); $http->on("request", function ($request, $response) { $response->header("Content-Type", "text/plain"); $response->end("Hello Worldn"); }); $http->start();
  • 16. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 16/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. EXPRESSIVEWITHSWOOLEEXPRESSIVEWITHSWOOLE Use library Install: Usage: wshafer/swoole-expressive composer require wshafer/swoole-expressive:dev-master vendor/bin/swoole-expressive --host=0.0.0.0 --port=8080
  • 17. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 17/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. HTTPSERVERFORPSR-7HTTPSERVERFORPSR-7 use SwooleHttpRequest; use SwooleHttpResponse $http = new swoole_http_server($host, $port); $http->on( 'request', function (Request $request, Response $response) use ($app, $psr7Request, $swooleResponse) { $psrResponse = $app->handle($psr7Request->from($request)); $swooleResponse->fromPsr7($psrResponse, $response); } ); $http->start();
  • 18. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 18/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. SWOOLEVS.NGINXVS.APACHESWOOLEVS.NGINXVS.APACHE
  • 19. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 19/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. BENCHMARKRESULTSBENCHMARKRESULTS Expressive with Swoole runs 4x faster than nginx and Apache ( )source
  • 20. 5/14/2018 Speed up web APIs with Expressive and Swoole - phpDay 2018 https://www.zimuel.it/slides/phpday2018/expressive_swoole?print-pdf#/ 20/20 © 2018 Rogue Wave Software, Inc. All Rights Reserved. THANKS!THANKS! Rate this talk at This work is licensed under a . I used to make this presentation. joind.in/talk/bef90 Creative Commons Attribution-ShareAlike 3.0 Unported License reveal.js