functions-framework-php icon indicating copy to clipboard operation
functions-framework-php copied to clipboard

Deploying to Cloud Functions ignores memory param

Open calsmith opened this issue 3 years ago • 5 comments

I'm having an issue with the PHP cloud function runtime ignoring custom memory values.

I'm deploying my function with 1GB of memory: gcloud functions deploy --runtime php74 \ --region=us-central1 \ --trigger-event google.storage.object.finalize \ --project=creator-testing \ --timeout=300 \ --memory=1024MB \ --trigger-resource collective-temp-uploads \ --entry-point=begin \ handle-user-uploads

But the GCP logs always show that the memory flag was ignored and defaults to 256MB: [serve] Serve started. [serve] Args: {runtimeLanguage:php runtimeName:php74 memoryMB: positional:[vendor/bin/router.php]} [serve] Could not parse memory limit; defaulting to 256MiB. [serve] workersFromArgs: memoryMB:256 flagAppWorkers:0 workers:2

The GCP front-end UI does correctly show the specified 1GB, but my function does not actually have access to that much memory. I've tried other values like "1GB" etc, but this error message always appears in the logs.

Is this a limitation of the beta/preview release?

Any tips on how to fix this issue?

calsmith avatar Jun 16 '21 09:06 calsmith

This seems like a potential issue with the Cloud Functions Runtime, and not with this framework. I'll try to get you an answer, but in the meantime, have you tried including an ini file with the memory_limit increased?

bshaffer avatar Jul 12 '21 16:07 bshaffer

Unfortunately the error still occurs with a memory limit defined in php.ini

Is there another place where we can report this error?

calsmith avatar Jul 28 '21 09:07 calsmith

any solution to this?

vinkev avatar Jun 28 '22 07:06 vinkev

This issue still occurs • bump?

calsmith avatar Jun 28 '22 07:06 calsmith

I figure out how to solve this. In order to raise the memory limit of each worker you need to setup extra environment key as GAE_MEMORY_MB in your case, add

--set-env-vars GAE_MEMORY_MB=1024

you could take a look of full complete extra PHP environment variable at https://cloud.google.com/appengine/docs/standard/php-gen2/runtime#enabled_extensions

vinkev avatar Jun 28 '22 09:06 vinkev

Hey all,

I've tested this in both gen1 and gen2 with 1GiB memory and I think it's no longer occurring.

The body I'm testing it with was:

  $mem_env = getenv('GAE_MEMORY_MB');
  $memory_limit = ini_get('memory_limit');
  return sprintf('Memory Limit, ini: %s, env: %s', $memory_limit, $mem_env);

And I'm seeing the following output:

DEFAULT 2023-09-25T19:22:37.421571Z [resource.labels.functionName: function-6] [serve] Serve started.
DEFAULT 2023-09-25T19:22:37.421873Z [resource.labels.functionName: function-6] [serve] Args: {runtimeLanguage:php runtimeName:php74 memoryMB: positional:[vendor/bin/router.php]}
DEFAULT 2023-09-25T19:22:37.425144Z [resource.labels.functionName: function-6] [serve] Running /bin/sh -c exec php-fpm -R --nodaemonize --fpm-config /tmp/serve-php/php-fpm.conf

Looking through the buildpacks, it seems like the thing we used to generate the php.ini and php-fpm.conf config have been updated.

Closing for now, if this is still an issue please re-open with a little snippet we can use to prove the error is still occurring. Thanks!

josephlewis42 avatar Sep 25 '23 19:09 josephlewis42