Skip to content

patrickjahns/nuclio-php-runtime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nuclio-php-runtime

Runtime for php applications in nuclio

This repository provides a small shim written in golang, which forwards a nuclio event via fcgi to php-fpm through a unix socket.

How does it work

On the first request (coldstart) received by the function a php-fpm server will be started. The php-fpm server is configured to listen on a linux socket ( /var/task/fpm.sock). The request will be forwarded to fpm via the socket and the response will be returned to the clients

Subsequent request to the function will profit from the already running php-fpm server and handle requests faster.

Configuration & Caveats

The current version is opinionated:

  • Per default we assume that a central php script is provided which all requests will be handled (it is responsible for application internal routing). The script can be defined in the Dockerfile (PHP_SCRIPT) or later via the environment vars in the nuclio interface
  • It assumes that the working directory of the function is /var/task - thus the fpm configuration file as well as the source code is put there
  • The Dockerfile utilizes the standard php:fpm container as the basis and adds the nuclio specific options. If you use a different container, please ensure you set PHP_FPM_BIN to the correct path.

Example

The repository contains a example Dockerfile on how to utilize the handler. It can easily be deployed by building the docker image via:

cd example && docker build -t nuclio-php-example:latest

Once it is build, it can be deployed with the following nuclio configuration

apiVersion: "nuclio.io/v1"
kind: NuclioFunction
metadata:
  name: php-example
spec:
  image: nuclio-php-example:latest
  handler: main:Handler
  runtime: golang

For more information on deploying functions via Dockerfiles please refer to the nuclio documentation:

There is also a demo project utilizing the symfony framework

Other Projects

  • bref.sh PHP Runtime for AWS Lambda

Authors

License

Apache

Copyright

Copyright (c) 2019 Patrick Jahns