PHP Cloud Functions on Google Cloud Platform with “Functions Framework for PHP”

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 …


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!


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » PHP Cloud Functions on Google Cloud Platform with “Functions Framework for PHP”." Bramus! | Sciencx - Monday April 26, 2021, https://www.scien.cx/2021/04/26/php-cloud-functions-on-google-cloud-platform-with-functions-framework-for-php/
HARVARD
Bramus! | Sciencx Monday April 26, 2021 » PHP Cloud Functions on Google Cloud Platform with “Functions Framework for PHP”., viewed ,<https://www.scien.cx/2021/04/26/php-cloud-functions-on-google-cloud-platform-with-functions-framework-for-php/>
VANCOUVER
Bramus! | Sciencx - » PHP Cloud Functions on Google Cloud Platform with “Functions Framework for PHP”. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/26/php-cloud-functions-on-google-cloud-platform-with-functions-framework-for-php/
CHICAGO
" » PHP Cloud Functions on Google Cloud Platform with “Functions Framework for PHP”." Bramus! | Sciencx - Accessed . https://www.scien.cx/2021/04/26/php-cloud-functions-on-google-cloud-platform-with-functions-framework-for-php/
IEEE
" » PHP Cloud Functions on Google Cloud Platform with “Functions Framework for PHP”." Bramus! | Sciencx [Online]. Available: https://www.scien.cx/2021/04/26/php-cloud-functions-on-google-cloud-platform-with-functions-framework-for-php/. [Accessed: ]
rf:citation
» PHP Cloud Functions on Google Cloud Platform with “Functions Framework for PHP” | Bramus! | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.