SlideShare a Scribd company logo
Globalcode – Open4education
PHP as a Service
Serverless PHP applications
Globalcode – Open4education
gitlab.com/pvgomes
Paulo Victor Gomes - pvgomes
Tech Lead at Z-Tech - AB
Inbev/AmBev
@_pvgomes
former CTO at Mundo Verde and Natue, former software
engineering at Dafiti, Kanui, Tricae and Rocket Internet
github.com/pvgomes
pvgomes
Globalcode – Open4education
What is Serverless?
Serverless Computing still uses servers, but
you no longer have to worry about managing
them
Globalcode – Open4education
Key Features and Benefits
Globalcode – Open4education
Key Features and Benefits
● No Server Management
Globalcode – Open4education
Key Features and Benefits
● No Server Management
● Easy & Efficient Scaling
Globalcode – Open4education
Key Features and Benefits
● No Server Management
● Easy & Efficient Scaling
● Built in High Availability and Fault Tolerance
Globalcode – Open4education
Key Features and Benefits
● No Server Management
● Easy & Efficient Scaling
● Built in High Availability and Fault Tolerance
● Service Integration
Globalcode – Open4education
Key Features and Benefits
● No Server Management
● Easy & Efficient Scaling
● Built in High Availability and Fault Tolerance
● Service Integration
● Pay as you Go
Globalcode – Open4education
How Serverless Works?
Globalcode – Open4education
Serverless Infrastructure Providers
Globalcode – Open4education
The Major players
google trends
Globalcode – Open4education
Some Serverless Services in AWS
Globalcode – Open4education
AWS Lambda Hello World
Globalcode – Open4education
AWS Lambda Hello World
Globalcode – Open4education
AWS Lambda Hello World
Globalcode – Open4education
A simples AWS Lambda - Example
https://github.com/pvgomes/slack-lambda
Globalcode – Open4education
A simples AWS Lambda - Code
Globalcode – Open4education
A simples AWS Lambda - Code
Globalcode – Open4education
A simples AWS Lambda - Example
/natuelabs wiki
Globalcode – Open4education
A simples AWS Lambda - Code
class Wiki(Command):
def execute(self, argument):
try:
scopes = ["https://www.googleapis.com/auth/drive",...]
secret_file = os.path.join(parent_dir, '../client.json')
credentials = Credentials.from_service_account_file(secret_file, scopes=scopes)
service = discovery.build('sheets', 'v4', credentials=credentials)
range_name = "wiki!B2:B40"
request = service.spreadsheets().values().get(spreadsheetId=id, range=range_name)
response = request.execute()
wiki = ""
values = response.get('values')
for value in values:
wiki = wiki + ''.join(value) + "n"
return wiki
except OSError as e:
return str(e)
Globalcode – Open4education
A simples AWS Lambda - Example
Globalcode – Open4education
A simples AWS Lambda - “Deploy”
Package the code
Upload with aws cli
Globalcode – Open4education
Serverless Frameworks
https://serverless.com
AWS Serverless Application Model
https://aws.amazon.com/serverless/sam
Globalcode – Open4education
Serverless + AWS Lambda
Globalcode – Open4education
Serverless + AWS Lambda
Globalcode – Open4education
Serverless + AWS Lambda
Globalcode – Open4education
What about PHP ?
Globalcode – Open4education
PHP as a Service
1 request = 1 process
Globalcode – Open4education
PHP as a Service
PHP is faas-ready
Globalcode – Open4education
What about AWS Lambda and PHP?
Globalcode – Open4education
AWS lambda does not support PHP
Globalcode – Open4education
NodeJS PHP Handler
Globalcode – Open4education
Is that ok for you?
Globalcode – Open4education
AWS Lambda Layers
Globalcode – Open4education
Compile the desired version of PHP
Globalcode – Open4education
Compile the desired version of PHP
Globalcode – Open4education
Compile the desired version of PHP
Globalcode – Open4education
Compile the desired version of PHP
Globalcode – Open4education
Upload your layer
Globalcode – Open4education
Upload your layer
Globalcode – Open4education
Create your functions
Install using composer
Init a sample function
<?php
function handler($event)
{
return "Hello, {$event['name']}!";
}
Globalcode – Open4education
Create AWS S3 deployment bucket
aws s3 mb s3://phptdc
Globalcode – Open4education
Package artifacts
sam package 
--template-file template.yaml 
--output-template-file serverless-output.yaml 
--s3-bucket phptdc
Globalcode – Open4education
Deploy package
sam deploy 
--template-file serverless-output.yaml 
--stack-name my-first-php-lambda-layer 
--capabilities CAPABILITY_IAM
Globalcode – Open4education
What?
Globalcode – Open4education
PHP community never sleeps
Globalcode – Open4education
Bref.sh
Globalcode – Open4education
Bref Installation
Install using composer
Init a sample function
Install Bref
composer require bref/bref:0.4.1
Init a sample function
vendor/bin/bref init
Globalcode – Open4education
Bref Sample
Globalcode – Open4education
Bref Sample
Globalcode – Open4education
template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: ''
Resources:
TdcFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: 'tdc-function'
Description: ''
CodeUri: .
Handler: index.php
Timeout: 30 # in seconds (API Gateway has a timeout of 30 seconds)
MemorySize: 1024 # The memory size is related to the pricing and CPU power
Runtime: provided
Layers:
- 'arn:aws:lambda:us-east-1:209497400698:layer:php-73-fpm:7'
Globalcode – Open4education
template.yaml - events
...
Events:
# The function will match all HTTP URLs
HttpRoot:
Type: Api
Properties:
Path: /
Method: ANY
HttpSubPaths:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
Globalcode – Open4education
index.php
<?php
$date = date('d/m/Y H:i:s');
$title = <<<EOT
<h1>PHP as a Service</h1>
<p> TDC 2019 %s </p>
<img src="https://s3-sa-east-
1.amazonaws.com/thedevconf/2019/img/divulgacao/saopaulo/banner-
TDC2019-sao-paulo-180x150.png">
EOT;
echo sprintf($title, $date);
Globalcode – Open4education
Lambda run locally
sam local start-api
Globalcode – Open4education
Lambda run locally
Globalcode – Open4education
SAM uses docker to simulate Lambda
Before/After request
During request
Globalcode – Open4education
SAM uses docker to simulate Lambda
Globalcode – Open4education
Bref deployment - package artifacts
sam package 
--template-file template.yaml 
--output-template-file serverless-output.yaml 
--s3-bucket phptdc
Globalcode – Open4education
Bref deployment - deploy package
sam deploy 
--template-file serverless-output.yaml 
--stack-name tdc-functions 
--capabilities CAPABILITY_IAM
Globalcode – Open4education
Our lambda is deployed
Globalcode – Open4education
AWS cli - stack information
aws cloudformation 
describe-stacks --stack-name tdc-functions
Globalcode – Open4education
AWS cli - stack information
{
"Stacks": [
{
"StackName": "tdc-functions",
…..
"Outputs": [
{ "OutputValue":"https://z6lppb8vl9.execute-api.us-east-
1.amazonaws.com/Prod/",
}
]}
]
}
Globalcode – Open4education
API Gateway URL / test me
https://z6lppb8vl9.execute-api.us-east-1.amazonaws.com/Prod/
Globalcode – Open4education
Bref with Symfony
https://bref.sh/docs/frameworks/symfony.html
Globalcode – Open4education
Create from scratch
Create path
mkdir symfony-serverless
Install symfony
composer create-project symfony/website-skeleton symfony-serverless
Start server
symfony-serverless/bin/console server:start
Globalcode – Open4education
Create from scratch
Globalcode – Open4education
First page - Lucky Number
Create Lucky controller (src/Controller/LuckyController.php)
<?php
namespace AppController;
use SymfonyComponentRoutingAnnotationRoute;
use SymfonyBundleFrameworkBundleControllerAbstractController;
class LuckyController extends AbstractController
{
/**
* @Route("/")
*/
public function number()
{
$number = random_int(0, 100);
return $this->render('lucky/number.html.twig', [
'number' => $number,
]);
}
}
Globalcode – Open4education
Again - Built in
Globalcode – Open4education
Setup Bref
Install bref into project
composer required bref/bref:0.4.1
Create lambda template
template.yaml
Content
https://gist.github.com/pvgomes/59632c00d3216fd78769492d6f82e130
Globalcode – Open4education
Change log path into src/Kernel.php
...
public function getLogDir()
{
if (getenv('LAMBDA_TASK_ROOT') !== false) {
return '/tmp/log/';
}
return $this->getProjectDir().'/var/log';
}
public function getCacheDir()
{
if (getenv('LAMBDA_TASK_ROOT') !== false) {
return '/tmp/cache/'.$this->environment;
}
return $this->getProjectDir().'/var/cache/'.$this->environment;
}
Globalcode – Open4education
Run it locally with SAM
Globalcode – Open4education
Bref deployment - package artifacts
sam package 
--template-file template.yaml 
--output-template-file serverless-output.yaml 
--s3-bucket phptdc
Globalcode – Open4education
Bref deployment - deploy package
sam deploy 
--template-file serverless-output.yaml 
--stack-name symfony-serverless 
--capabilities CAPABILITY_IAM
Globalcode – Open4education
Done / test me
https://j0znkm50u0.execute-api.us-east-1.amazonaws.com/Prod/
Globalcode – Open4education
Bref new features - 0.5.0
Bref now recommends Serverless instead of SAM
Changes: https://github.com/brefphp/bref/releases/tag/0.5.0
Thank you!
@_pvgomes
pvgomes.com/videos

More Related Content

What's hot (20)

PDF
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver
 
PDF
OpenSouthCode 2018 - Integrating your applications easily with Apache Camel
José Román Martín Gil
 
PDF
DEVNET-2006 Coding 210: Parsing JSON in C++
Cisco DevNet
 
PDF
Improve your Java Environment with Docker
HanoiJUG
 
PDF
Drone CI
Thomas Boerger
 
ODP
Apache Camel workshop at BarcelonaJUG in January 2014
Claus Ibsen
 
PPTX
Zend con 2016 bdd with behat for beginners
Adam Englander
 
PDF
Automate Your Automation | DrupalCon Vienna
Pantheon
 
PDF
Seven perilous pitfalls to avoid with Java | DevNation Tech Talk
Red Hat Developers
 
PDF
Gitlab ci, cncf.sk
Juraj Hantak
 
PPTX
gRPC, GraphQL, REST - Which API Tech to use - API Conference Berlin oct 20
Phil Wilkins
 
PDF
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver
 
PDF
Natively clouded Journey
Haggai Philip Zagury
 
PDF
Practical PHP Deployment with Jenkins
Adam Culp
 
PDF
PuppetConf 2016: Using Puppet with Kubernetes and OpenShift – Diane Mueller, ...
Puppet
 
PDF
Git ops & Continuous Infrastructure with terra*
Haggai Philip Zagury
 
PDF
The 2nd half. Scaling to the next^2
Haggai Philip Zagury
 
PPTX
It's a Breeze to develop Airflow (Cloud Native Warsaw)
Jarek Potiuk
 
PDF
Deep Learning - Continuous Operations
Haggai Philip Zagury
 
PDF
Docker based-Pipelines with Codefresh
Codefresh
 
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver
 
OpenSouthCode 2018 - Integrating your applications easily with Apache Camel
José Román Martín Gil
 
DEVNET-2006 Coding 210: Parsing JSON in C++
Cisco DevNet
 
Improve your Java Environment with Docker
HanoiJUG
 
Drone CI
Thomas Boerger
 
Apache Camel workshop at BarcelonaJUG in January 2014
Claus Ibsen
 
Zend con 2016 bdd with behat for beginners
Adam Englander
 
Automate Your Automation | DrupalCon Vienna
Pantheon
 
Seven perilous pitfalls to avoid with Java | DevNation Tech Talk
Red Hat Developers
 
Gitlab ci, cncf.sk
Juraj Hantak
 
gRPC, GraphQL, REST - Which API Tech to use - API Conference Berlin oct 20
Phil Wilkins
 
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver
 
Natively clouded Journey
Haggai Philip Zagury
 
Practical PHP Deployment with Jenkins
Adam Culp
 
PuppetConf 2016: Using Puppet with Kubernetes and OpenShift – Diane Mueller, ...
Puppet
 
Git ops & Continuous Infrastructure with terra*
Haggai Philip Zagury
 
The 2nd half. Scaling to the next^2
Haggai Philip Zagury
 
It's a Breeze to develop Airflow (Cloud Native Warsaw)
Jarek Potiuk
 
Deep Learning - Continuous Operations
Haggai Philip Zagury
 
Docker based-Pipelines with Codefresh
Codefresh
 

Similar to PHP as a Service TDC2019 (6)

PPTX
Functional as a service TDC 2020
Paulo Victor Gomes
 
PDF
Node.js cluster
Derek Willian Stavis
 
PDF
Tdc2013 trilha cloud
Marcondes Maçaneiro
 
PPTX
Open Source and GitHub for Teaching with Software Development Projects
Daniel Nüst
 
PDF
Genomics on aws-webinar-april2018
Brendan Bouffler
 
PDF
Building and deploying LLM applications with Apache Airflow
Kaxil Naik
 
Functional as a service TDC 2020
Paulo Victor Gomes
 
Node.js cluster
Derek Willian Stavis
 
Tdc2013 trilha cloud
Marcondes Maçaneiro
 
Open Source and GitHub for Teaching with Software Development Projects
Daniel Nüst
 
Genomics on aws-webinar-april2018
Brendan Bouffler
 
Building and deploying LLM applications with Apache Airflow
Kaxil Naik
 
Ad

More from Paulo Victor Gomes (8)

PPTX
PHP as a Service
Paulo Victor Gomes
 
PDF
Stacks Cloud - Digital Ocean
Paulo Victor Gomes
 
PDF
O mundo do e commerce visto pela ótica do PHP
Paulo Victor Gomes
 
PDF
Essay about event driven architecture
Paulo Victor Gomes
 
PDF
Hexagonal architecture in PHP
Paulo Victor Gomes
 
PDF
DDD in PHP
Paulo Victor Gomes
 
PDF
PHP e Redis
Paulo Victor Gomes
 
PDF
Domain Driven Design PHP TDC2014
Paulo Victor Gomes
 
PHP as a Service
Paulo Victor Gomes
 
Stacks Cloud - Digital Ocean
Paulo Victor Gomes
 
O mundo do e commerce visto pela ótica do PHP
Paulo Victor Gomes
 
Essay about event driven architecture
Paulo Victor Gomes
 
Hexagonal architecture in PHP
Paulo Victor Gomes
 
DDD in PHP
Paulo Victor Gomes
 
PHP e Redis
Paulo Victor Gomes
 
Domain Driven Design PHP TDC2014
Paulo Victor Gomes
 
Ad

Recently uploaded (20)

PDF
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Top Managed Service Providers in Los Angeles
Captain IT
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 

PHP as a Service TDC2019