Hello,
I've searched everywhere on Google and here, but I couldn't seem to find how to execute Cloud Functions on PHP.
Is it available here? Can please someone lead me to the correct documentation/implementation.
Thank you!
Edit:
I would really appreciate if you guys can help me out: https://stackoverflow.com/questions/54797672/call-firebase-cloud-function-that-requires-authentication-using-service-account
it is not available in PHP, only on Node (6, 8), Go and Python
Hi @lambasoft,
Cloud Functions are not included in Google Cloud PHP, but are supported by google/api-client.
Here is an example showing how to execute a cloud function:
$projectId = '[YOUR PROJECT ID]';
$locationId = '[LOCATION ID]';
$functionId = '[YOUR FUNCTION ID]';
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope([
Google_Service_CloudFunctions::CLOUD_PLATFORM
]);
$functions = new Google_Service_CloudFunctions($client);
$call = new Google_Service_CloudFunctions_CallFunctionRequest();
$name = sprintf(
'projects/%s/locations/%s/functions/%s',
$projectId,
$locationId,
$functionId
);
$response = $functions->projects_locations_functions->callProjectsLocationsFunctions($name, $call);
print_r($response);
If your function requires data to be provided, you can set that in the Google_Service_CloudFunctions_CallFunctionRequest constructor:
$call = new Google_Service_CloudFunctions_CallFunctionRequest([
'data' => json_encode([
'message' => 'Hello World!'
])
]);
You will receive an instance of Google_Service_CloudFunctions_CallFunctionResponse as your response.
Most helpful comment
Hi @lambasoft,
Cloud Functions are not included in Google Cloud PHP, but are supported by
google/api-client.Here is an example showing how to execute a cloud function:
If your function requires data to be provided, you can set that in the
Google_Service_CloudFunctions_CallFunctionRequestconstructor:You will receive an instance of
Google_Service_CloudFunctions_CallFunctionResponseas your response.