2

Is it possible to execute a Google Cloud Function and wait for it's results through PHP?

I have searched the documentations at:

But none had integration for Cloud Functions.

9
  • Your question fits best at a sister site, selected from here: stackexchange.com/sites# Commented Feb 20, 2019 at 23:25
  • 4
    @ZF007 - This question fits on StackOverflow as it is a programming question. He does not need to move his post. Commented Feb 20, 2019 at 23:30
  • 1
    @ZF007 I think StackOverflow fits best Commented Feb 20, 2019 at 23:31
  • At "learn more" below on cloud.google.com/php/?hl=en page you'll stumble upon the php stuff... including a PHP SDK for it. Finding took me 10 seconds (incl. getting a grasp if it's looking relevant). So.. does this question still fits here on SO... Commented Feb 20, 2019 at 23:40
  • Google has a fairly good set of PHP SDKs for most Google Cloud services. Cloud Functions is not one of them. cloud.google.com/php/docs/reference However, Cloud Functions can be called from HTTP Triggers, which means that you can use any good HTTP library (such as Guzzle) to call Cloud Functions and wait for the result. Otherwise you can use the low level API and use HTTP requests in PHP: cloud.google.com/functions/docs/reference/rest/v1/… I am posting as a comment in case Google has something that I am not aware of that has not been announced. Commented Feb 20, 2019 at 23:46

2 Answers 2

2

You can create an HTTP triggered Cloud Function. For more information go to HTTP Triggers documentation. Then make an http request form your PHP code using the function's trigger URL. To see it go to Cloud Functions page in Google Cloud Console. Click on your Cloud Function's name and the Function details page will open. Go to the Trigger tab and under URL you can see the link to execute the Cloud Function.

An PHP example to do so could be as follows (It is one of many, and that is what worked for me): Run sudo apt-get install php-curl to install php curl

Use the following PHP code:

<?php global $url; //The Cloud Function's trigger URL $url = "www.[FUNCTION_ZONE]-[PROJECT_ID].cloudfunctions.net/[FUNCTION_NAME]"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); // Set so curl_exec returns the result instead of outputting it. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Get the response and close the channel. $response = curl_exec($ch); echo "Printing response: \n\n"; echo $response; curl_close($ch); 
Sign up to request clarification or add additional context in comments.

Comments

0

This should now be the preferred integration for PHP:

https://cloud.google.com/php/docs/reference/cloud-functions/latest

and can be installed via composer:

composer require google/cloud-functions 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.