google/cloud-functions-framework
is an open source FaaS (Function as a Service) Framework for writing portable PHP functions.
An example function looks like this:
<?php
use Symfony\Component\HttpFoundation\Request;
function helloHttp(Request $request)
{
return "Hello World from PHP HTTP function!" . PHP_EOL;
}
One can invoke it locally by executing the included router as follows:
export FUNCTION_TARGET=helloHttp
export FUNCTION_SIGNATURE_TYPE=http
export FUNCTION_SOURCE=index.php
php -S localhost:8080 vendor/bin/router.php
Alternatively you can run it in a Docker container (which you can then deploy to Cloud Run):
docker build . \
-f vendor/google/cloud-functions-framework/examples/hello/Dockerfile \
-t my-cloud-function
docker run -p 8080:8080 \
-e FUNCTION_TARGET=helloHttp \
-e FUNCTION_SIGNATURE_TYPE=http \
my-cloud-function
Installation per Composer:
composer require google/cloud-functions-framework
google/cloud-functions-framework
→
⚠️ There is a sample Dockerfile
included with the repo, but a first glance tells me it needs some polishing as it uses a full blown GAE_RUNTIME
Docker base image and directly installs the composer dependencies into the image itself instead of relying on multi-stage builds.