This content originally appeared on Bram.us and was authored by Bramus!
Google Cloud Platform has launched official support for PHP Cloud Functions using Functions Framework for PHP.
With it, an HTTP Cloud Function becomes as simple as this:
use Psr\Http\Message\ServerRequestInterface;
function helloHttp(ServerRequestInterface $request): string
{
$queryString = $request->getQueryParams();
$name = $queryString['name'] ?? $name;
return sprintf('Hello, %s!', $name);
}
Functions that respond to Cloud Events can work with a \Google\CloudFunctions\CloudEvent
instance:
use Google\CloudFunctions\CloudEvent;
function helloworldPubsub(CloudEvent $event): void
{
$name = 'World';
$cloudEventData = $event->getData();
if (!empty($cloudEventData['data'])) {
$name = base64_decode($cloudEventData['data']);
}
// …
}
Installation per Composer
composer require google/cloud-functions-framework
Functions Framework for PHP →
Introducing PHP on Cloud Functions →
This content originally appeared on Bram.us and was authored by Bramus!
Bramus! | Sciencx (2021-04-26T20:54:49+00:00) PHP Cloud Functions on Google Cloud Platform with “Functions Framework for PHP”. Retrieved from https://www.scien.cx/2021/04/26/php-cloud-functions-on-google-cloud-platform-with-functions-framework-for-php/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.