Ddev: Provide custom php configs for both cli and fpm, especially to allow separate memory_limit

Created on 10 Sep 2019  路  7Comments  路  Source: drud/ddev

At the moment the custom php config is copied automatically to:

/etc/php/7.2/apache2/conf.d
/etc/php/7.2/fpm/conf.d
/etc/php/7.2/cli/conf.d

This is already nice, but it does not allow to set custom config per cli/fpm. For example we'd like to set different memory limits for cli and fpm but we cannot achieve it with current behavior. Would be great if there is a way to scale configs so fpm and cli can have different settings.

Most helpful comment

Thanks for explaining, that's totally reasonable, and a reasonable request, although it hasn't been a stumbling block for most people (who are less careful about memory than you I think).

Here's a workaround you can use right now to solve this problem; add this post-start hook to your .ddev/config.yaml:

hooks:
 post-start:
   - exec: perl -pi -e 's/memory_limit.*$/memory_limit = -1/' /etc/php/${DDEV_PHP_VERSION}/cli/conf.d/*.ini

All 7 comments

Can you say a little about why you want limits at all? For most people, in a dev environment, memory limits don't matter.

Yes, I can. Limits do matter even for dev environment because if you have a bug like endless loop, then drush command can eat all of your memory and dock (and then computer) dies. There should be a way to limit/configure a cli. And ideally to set different limits for fpm as it's required to have different limits for cli and fpm.

We already encountered many memory problems and we need to configure limits to more realistic values so we know for example fpm is not overeating resources. With current possibilities we are able to set both cli and fpm to 1GB. This is however not sufficient either. Drupal fpm instance should be able to run with much less memory, like 256M. Even for dev env, so we can track resource usage. Once this border is crossed we should notice it and either reconfigure the value or fix the potential ineffective code which caused it.

Thanks for explaining, that's totally reasonable, and a reasonable request, although it hasn't been a stumbling block for most people (who are less careful about memory than you I think).

Here's a workaround you can use right now to solve this problem; add this post-start hook to your .ddev/config.yaml:

hooks:
 post-start:
   - exec: perl -pi -e 's/memory_limit.*$/memory_limit = -1/' /etc/php/${DDEV_PHP_VERSION}/cli/conf.d/*.ini

Another benefit / consequence of this change would be that Xdebug could be toggled on/off separately as well.

If/when these configs are split up, the ddev . enable_xdebug|disable_xdebug commands should probably be augmented to allow targeting cli, fpm, or both.

Would also love to change php memory_limit but only for fpm (not cli).
Common scenario: On the live webserver we have a memory_limit (for fpm). On more complex websites we already ran into limit which could have been avoided if we would have hit that already in our local environment (ddev).
Important here is that cli-commands are ok to consume more memory as they perform more complex tasks, thats whay cli memory_limit is unlimited on live-system and I would love to have the same config in ddev.
Will use your workaround with the post-start hook but this feature request is very reasonable I think.

You could also use .ddev/web-build/Dockerfile to override the php.ini, then it wouldn't require the hook.

Thanks

Was this page helpful?
0 / 5 - 0 ratings