SlideShare uma empresa Scribd logo
1 de 26
Baixar para ler offline
MIDDLEWARE	WEB	APIS	IN	PHP	7.X
Jan	Burkl
Solution	Consulting	Manager
,	Dresden,	22nd	September	2017
Rogue	Wave	Software
php	developer	day	2017
PHP
PHP:	Hypertext	Preprocessor
The	most	popular	server-side	language:	PHP	is
used	by	82.6%	of	all	the	websites	(source:
)
Used	by	Facebook,	Wikipedia,	Yahoo,	Etsy,
Flickr,	Digg,	etc
22	years	of	usage,	since	1995
Full	OOP	support	since	PHP	5
w3techs.com
PHP	7
Released:	3	December	2015
Previous	major	was	 ,	13	July	2004
Skipped	PHP	6:	Unicode	failure
Last	release	is	 	(3	Aug	2017)
PHP	5
7.1.8
PHP	7	PERFORMANCE
PHP	7	is	also	faster	than	 !Python	3
BENCHMARK
PHP	5.6 PHP	7
Memory	Usage 428	MB 33	MB
Execution	time 0.49	sec 0.06	sec
$a	=	[];
for	($i	=	0;	$i	<	1000000;	$i++)	{
		$a[$i]	=	["hello"];
}
echo	memory_get_usage(true);
MOVING	TO	PHP	7
Badoo	saved	one	million	dollars	switching	to	PHP
7	( )
Tumblr	reduced	the	latency	and	CPU	load	by	half
moving	to	PHP	7	( )
Dailymotion	handles	twice	more	traffic	with
same	infrastructure	switching	to	PHP	7	( )
source
source
source
PHP	7	IS	NOT	ONLY	FAST!
Return	and	Scalar	Type	Declarations
Improved	Exception	hierarchy
Many	fatal	errors	converted	to	Exceptions
Secure	random	number	generator
Authenticated	encryption	AEAD	(PHP	7.1+)
Nullable	types	(PHP	7.1+)
and	 !more
WEB	APIS	IN	PHP	7
HTTP	IN/OUT
EXAMPLE
Request:
Response:
GET	/api/version
HTTP/1.1	200	OK
Connection:	close
Content-Length:	17
Content-Type:	application/json
{
		"version":	"1.0"
}
MIDDLEWARE
A	function	that	gets	a	request	and	generates	a
response
use	PsrHttpMessageServerRequestInterface	as	Request;
use	InteropHttpServerMiddlewareDelegateInterface;
function	(Request	$request,	DelegateInterface	$next)
{
				//	doing	something	with	$request...
				//	for	instance	calling	the	delegate	middleware	$next
				$response	=	$next->process($request);
				//	manipulate	the	$response
				return	$response;
}
DELEGATEINTERFACE
DelegateInterface	is	part	of	 	HTTP	Middleware	proposal
namespace	InteropHttpServerMiddleware;
use	PsrHttpMessageResponseInterface;
use	PsrHttpMessageServerRequestInterface;
interface	DelegateInterface
{
				/**
					*	@return	ResponseInterface;
					*/
				public	function	process(ServerRequestInterface	$request);
}
PSR-15
EXPRESSIVE	2.0
The	PHP	framework	for	Middleware	applications
PSR-7	HTTP	Message	support	(using	
)
Support	of	lambda	middleware	(PSR-15)	and
double	pass	($request,	$response,	$next)
Piping	workflow	(using	 )
Features:	routing,	dependency	injection,
templating,	error	handling
Last	release	2.0.3,	28th	March	2017
zend-
diactoros
zend-stratigility
INSTALLATION
You	can	install	Expressive	2.0	using	 :
Choose	the	default	options	during	the	installation
composer
composer	create-project	
		zendframework/zend-expressive-skeleton	api
DEFAULT
The	skeleton	has	2	URL	as	example:	/	and
/api/ping
The	routes	are	registered	in	/config/routes.php
The	middleware	actions	are	stored	in
/src/App/Action
ROUTES
/config/routes.php
$app->get('/',	AppActionHomePageAction::class,	'home');
$app->get('/api/ping',	AppActionPingAction::class,	'api.ping');
API	MIDDLEWARE
/src/App/Action/PingAction.php
namespace	AppAction;
use	InteropHttpServerMiddlewareDelegateInterface;
use	InteropHttpServerMiddlewareMiddlewareInterface;
use	ZendDiactorosResponseJsonResponse;
use	PsrHttpMessageServerRequestInterface;
class	PingAction	implements	MiddlewareInterface
{
				public	function	process(
								ServerRequestInterface	$request,
								DelegateInterface	$delegate
				)	{
								return	new	JsonResponse(['ack'	=>	time()]);
				}
}
PIPELINE	WORKFLOW
/config/pipeline.php
$app->pipe(ErrorHandler::class);
$app->pipe(ServerUrlMiddleware::class);
$app->pipeRoutingMiddleware();
$app->pipe(ImplicitHeadMiddleware::class);
$app->pipe(ImplicitOptionsMiddleware::class);
$app->pipe(UrlHelperMiddleware::class);
$app->pipeDispatchMiddleware();
$app->pipe(NotFoundHandler::class);
SERVICE	CONTAINER
/config/container.php
use	ZendServiceManagerConfig;
use	ZendServiceManagerServiceManager;
$config	=	require	__DIR__	.	'/config.php';
$container	=	new	ServiceManager();
$config	=	new	Config($config['dependencies']);
$config->configureServiceManager($container);
$container->setService('config',	$config);
return	$container;
THE	EXPRESSIVE	APP
/public/index.php
chdir(dirname(__DIR__));
require	'vendor/autoload.php';
call_user_func(function	()	{
				$container	=	require	'config/container.php';
				$app	=	$container->get(ZendExpressiveApplication::class
				require	'config/pipeline.php';
				require	'config/routes.php';
				$app->run();
});
ROUTE	A	REST	API
$app->route('/api/users[/{user-id}]',	[
				AuthenticationAuthenticationMiddleware::class,
				AuthorizationAuthorizationMiddleware::class,
				ApiActionUserAction::class
],	['GET',	'POST',	'PATCH',	'DELETE'],	'api.users');
//	or	route	each	HTTP	method
$app->get('/api/users[/{user-id}]',	...,	'api.users.get');
$app->post('/api/users',	...,	'api.users.post');
$app->patch('/api/users/{user-id}',	...,	'api.users.patch');
$app->delete('/api/users/{user-id}',	...,	'api.users.delete');
REST	DISPATCH	TRAIT
use	PsrHttpMessageServerRequestInterface;
use	InteropHttpServerMiddlewareDelegateInterface;
trait	RestDispatchTrait
{
				public	function	process(
								ServerRequestInterface	$request,
								DelegateInterface	$delegate
				)	{
								$method	=	strtolower($request->getMethod());
								if	(method_exists($this,	$method))	{
												return	$this->$method($request);
								}
								return	$response->withStatus(501);	//	Method	not	implem
				}
REST	MIDDLEWARE
ApiActionUserAction.php
class	UserAction	implements	MiddlewareInterface
{
				use	RestDispatchTrait;
				public	function	get(ServerRequestInterface	$request)
				{
								$id	=	$request->getAttribute('user-id',	false);
								$data	=	(false	===	$id)	?	/*	all	users	*/	:	/*	user	id	*/;
								return	new	JsonResponse($data);
				}
				public	function	post(ServerRequestInterface	$request){	...	}
				public	function	patch(ServerRequestInterface	$request){	...	}
				public	function	delete(ServerRequestInterface	$request){	...	
}
DANKE	SCHÖN
Slides:	http://5square.github.io/talks/
More	info:	
Contact	me:	jan.burkl	[at]	roguewave.com
Follow	me:	
Credits:	
This	work	is	licensed	under	a
.
I	used	 	to	make	this	presentation.
https://framework.zend.com/blog
@janatzend
@ezimuel
Creative	Commons	Attribution-ShareAlike	3.0	Unported	License
reveal.js

Mais conteúdo relacionado

Mais procurados

The future of server side JavaScript
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScript
Oleg Podsechin
 

Mais procurados (9)

The future of server side JavaScript
The future of server side JavaScriptThe future of server side JavaScript
The future of server side JavaScript
 
このPHP拡張がすごい!2017
このPHP拡張がすごい!2017このPHP拡張がすごい!2017
このPHP拡張がすごい!2017
 
Build Python CMS The Plone Way
Build Python CMS The Plone WayBuild Python CMS The Plone Way
Build Python CMS The Plone Way
 
openPOWERLINK over Xenomai
openPOWERLINK over XenomaiopenPOWERLINK over Xenomai
openPOWERLINK over Xenomai
 
Writing multi-language documentation using Sphinx
Writing multi-language documentation using SphinxWriting multi-language documentation using Sphinx
Writing multi-language documentation using Sphinx
 
Ikazuchi introduction for Europython 2011 LT
Ikazuchi introduction for Europython 2011 LTIkazuchi introduction for Europython 2011 LT
Ikazuchi introduction for Europython 2011 LT
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Development and deployment with composer and kite
Development and deployment with composer and kiteDevelopment and deployment with composer and kite
Development and deployment with composer and kite
 
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
 

Semelhante a Middleware web APIs in PHP 7.x

Applied+Web+Development+[Autosaved].pptx
Applied+Web+Development+[Autosaved].pptxApplied+Web+Development+[Autosaved].pptx
Applied+Web+Development+[Autosaved].pptx
voot1
 
Unit 1 php_basics
Unit 1 php_basicsUnit 1 php_basics
Unit 1 php_basics
Kumar
 

Semelhante a Middleware web APIs in PHP 7.x (20)

The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
PHP: Hypertext Preprocessor Introduction
PHP: Hypertext Preprocessor IntroductionPHP: Hypertext Preprocessor Introduction
PHP: Hypertext Preprocessor Introduction
 
Training ppt
Training pptTraining ppt
Training ppt
 
Php unit i
Php unit i Php unit i
Php unit i
 
Php intro
Php introPhp intro
Php intro
 
Php intro
Php introPhp intro
Php intro
 
Php intro
Php introPhp intro
Php intro
 
How PHP works
How PHP works How PHP works
How PHP works
 
PHP
PHPPHP
PHP
 
Integrating PHP With System-i using Web Services
Integrating PHP With System-i using Web ServicesIntegrating PHP With System-i using Web Services
Integrating PHP With System-i using Web Services
 
Applied+Web+Development+[Autosaved].pptx
Applied+Web+Development+[Autosaved].pptxApplied+Web+Development+[Autosaved].pptx
Applied+Web+Development+[Autosaved].pptx
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
 
PHP Course and Training
PHP Course and Training PHP Course and Training
PHP Course and Training
 
Php Training in Chandigarh
Php Training in ChandigarhPhp Training in Chandigarh
Php Training in Chandigarh
 
Building Desktop RIAs with JavaScript and PHP - ZendCon09
Building Desktop RIAs with JavaScript and PHP - ZendCon09Building Desktop RIAs with JavaScript and PHP - ZendCon09
Building Desktop RIAs with JavaScript and PHP - ZendCon09
 
Php On Windows
Php On WindowsPhp On Windows
Php On Windows
 
Unit 1 php_basics
Unit 1 php_basicsUnit 1 php_basics
Unit 1 php_basics
 
PHP Training in Chandigarh
PHP Training in ChandigarhPHP Training in Chandigarh
PHP Training in Chandigarh
 
PHP frameworks
PHP frameworks PHP frameworks
PHP frameworks
 

Mais de Zend by Rogue Wave Software

Mais de Zend by Rogue Wave Software (20)

Develop microservices in php
Develop microservices in phpDevelop microservices in php
Develop microservices in php
 
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
 
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
 
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
 
To PHP 7 and beyond
To PHP 7 and beyondTo PHP 7 and beyond
To PHP 7 and beyond
 
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018) Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (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)
The Sodium crypto library of PHP 7.2 (PHP Day 2018)
 
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)
 
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
 
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
 

Último

Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 

Último (20)

AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purityAPVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand5 Reasons Driving Warehouse Management Systems Demand
5 Reasons Driving Warehouse Management Systems Demand
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
 
How to pick right visual testing tool.pdf
How to pick right visual testing tool.pdfHow to pick right visual testing tool.pdf
How to pick right visual testing tool.pdf
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
The Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion ProductionThe Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion Production
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 

Middleware web APIs in PHP 7.x