Php drupal php memory limit

Increasing PHP memory limit (Possible Drupal override?) [closed]

Questions on programming, PHP, SQL, etc. that do not relate directly to Drupal are off-topic here, but can be asked on Stack Overflow.

Problem I’ve recently come across a problem with my dev version of Drupal where I realised the php memory limit isn’t high enough. I’ve changed the main php.ini files but they seem to be ignored and I can only increase the memory limit by putting the following line into sites/default/settings.php :

Altered php.ini in C:/XAMPP/php/php.ini

Altered php.ini in /etc/php5/apache2/php.ini

Altered php.ini in /etc/php5/cli/php.ini (checked this was correct ini file using php —ini )

I have a php.ini in my drupal root, but it has

which I’m pretty sure is no limit.

4 Answers 4

Drupal does not edit any php config settings. The memory_limit and what php.ini it is using depends on how your server is setup, there could be something else that is overriding your php.ini you are trying to set. You should use phpinfo() to find out what php.ini it is using and make sure the last occurrence of memory_limit is set to what ever you want.

Cheers for the confirmation. I couldn’t recreate the first two instances. Not sure what I did wrong, but I did find the explanation for nginx.

Changes to php.ini require that the server be restarted. Did you restart Apache after making those changes?

Drupal itself doesn’t change memory limits; your use of ini_set in settings.php is the best way to make the change through PHP execution, but many third-party hosts will not allow that setting to be overridden to overridden.

Finally, I’d recommend setting the memory limit to 512M as that reflects how semiconductor memory stores data. There’s no real functional advantage of this, though, just OCD 🙂

Ok so a bit of digging and here are the results. The short answer for the first two configs was I couldn’t replicate them. Maybe I’d forgotten to restart the server? Not sure.

The two paths I’d listed were the correct paths to change the php memory settings.

However for nginx there is a genuine answer:

You then have to restart the php process manager not the server because nginx doesn’t touch the php.

sudo service php5-fpm restart

The reason you have to edit /etc/php5/fpm/php.ini file is because /etc/php5/cli/php.ini is the command line php config file and only decides the config for any command line php functions.

Any php functions called by Drupal are processed by FPM and so use the php-fpm config file.

Источник

PHP memory limit in Drupal – Different methods to alter the settings

Often, an error like «Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes) can occur due to insufficient PHP memory limit.

Читайте также:  Null to boolean php

Also, this error signifies that Drupal required more memory than PHP was allowed to give it. Therefore, increasing the PHP memory limit helps to resolve the error.

At Bobcares, we often get requests from our customers to increase the PHP memory limit in Drupal as part of our Server Management Services.

Today, let’s get into the details on how our Support Engineers increase the PHP memory limit and fix related errors.

Need for PHP memory limit in Drupal

PHP makes it possible to use a default amount of memory while loading a website. In Drupal sites, the standard PHP memory requirements are very less. However, when the sites that run many contrib modules, or particularly memory-intensive ones.

At those times, we may get a white screen on the website or get the following error when uploading a file or running simultaneous processes.

Support Engineers fix the error by using different methods.

PHP memory limit Drupal – How we fix it

At Bobcares, where we have more than a decade of expertise in managing servers, we see many customers face problems with the PHP memory limit.

Now, let’s see the major reasons for the Error: Memory Size Exhausted and how our Support Engineers fix this error by increasing the PHP memory limit.

php.ini

This is one of the best methods to change the PHP memory limit in Drupal. We are changing the value in the server’s php.ini. So, This is advisable only in dedicated or VPS servers. Also, this change will affect all websites and PHP scripts on the server.

So, our Support Engineers make sure that the memory_limit parameter has set to enough memory value. If not, we edit the memory_limit parameter in the php.ini file. In addition, we make sure you use M to specify the number of megabytes.

Unfortunately, some server doesn’t have this section. Then, we add the following line at the end of the file.

memory_limit = 64M ; Maximum amount of memory a script may consume (64MB)

php.ini in the Drupal root folder

Another way to change the PHP memory limit is by adding the following line to a php.ini file in the Drupal root folder.

But, it will only work if PHP is running as CGI/FastCGI.

Through a hidden file .user.ini

Similarly, another useful file for changing the PHP memory limit is .user.ini. This is a hidden file that is located in the public_html folder.

If it is not in the public_html folder, we simply create the .user.ini file and add the following line to it.

.htaccess

Again, when the PHP is running as an Apache module, we can change the PHP memory limit via .htaccess file in the Drupal root directory.

We add the following line in .htaccess file.

php_value memory_limit 64M

Settings.php

When the Drupal is already installed, we can edit the file settings.php located in sites/default/. This approach will affect only the site using this file.

To change the PHP memory limit. We locate the PHP settings section and add the following line at the end of that section.

These are the various method to change the PHP memory limit.

Читайте также:  Html return to last page

[Need assistance change PHP memory limit? We’ll help you.]

Conclusion

In short, when the Drupal required more memory than PHP allowed, we can increase it in different ways such as alter the value in php.ini, .htaccess, .user.ini, etc. Today, we saw how our Support Engineers changed the PHP memory limit in Drupal.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

Источник

Conditionally increase the PHP memory limit on Drupal

On any Drupal project, you may face this kind of log:

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 6369280 bytes) in . 

This happens when a PHP process is reaching its memory limit and cannot achieve the requested task. This type of error can happen for many reasons including image manipulation, faulty migration or erroneously designed code to name a few examples. Before updating the memory allocated to PHP, it is always better to investigate the process causing the issue. This is important since increasing the memory may be a temporary patch, whereas the root cause could be due to erroneous code design.

There are however some operations such as image manipulation and media uploads that require more memory for PHP processes. The most straightforward fix is to increase the memory limit allowed per PHP process. This is valid if your entire application consumes a lot of memory, and globally requires more bandwidth. But in most cases, these are very specific operations which are reaching capacity limitations. Increasing the memory globally is not a good idea as it means less PHP processes will be capable of being performed in parallel. In short, if PHP has access to 1Gb and is configured to grant 512Mb to each PHP process, that would mean your application can only serve 2 requests in parallel. Keeping the memory limit to 128Mb and conditionally increasing the limit to 512Mb for the few expensive processes is a much better use of the available memory.

Why a module ?

As detailed on this Acquia KB article, it is possible to override the memory limit by adding code in the settings.php file. The caveat however is it requires code change, which may not be an easy task, and it may also lead to more complex and difficult code to maintain. The purpose of the module is to avoid adding complexity to the code, making it easier to maintain and configure via UI.

Some common situations where memory limitations can be an issue include:

  • Sites/default/files/styles/* which will generate an image variation and can be a bottleneck in case the original image is too heavy.
  • Admin/structure/taxonomy/management/*/overview which is the page listing the terms of a vocabulary and can be an issue when there are too many terms.
  • The submit of media upload form.

What does the module offer?

The Memory Limit Policy module which can be used to configure policies to conditionally increase the memory limit.

This module comes with different plugins to alter the memory based on:

  • The path
  • The presence of a query argument
  • The user role
  • The route name
  • The HTTP method
  • The Drush command (please note that it comes with some limitation).
Читайте также:  Java set default system properties

Plugins can be combined to be more restrictive on when to change memory limitations. They are designed to be easy to extend as policies are plugins which mean you can create your own policy if your conditions are very specific.

How to configure the module?

Say we want to increase the memory allocated to the process which generates image presets to 256Mb.

Once the module is enabled, policies are listed in Configuration > Performance > Memory Limit Policy > Policies (/admin/config/performance/memory-limit-policy/list).

Memory limit policy - list policies

To create a new policy, click the “+ Add policy” button.

It displays the first step of the policy configuration. You must give a name to the policy (“Image style” in our example) and choose the memory that the policy will apply when the conditions are met (“256M” in our example). The format must respect the shorthand byte format. 100Kb for 100 kilobytes, 100Mb for 100 megabytes and 1Gb for 1 gigabytes. This is the same format which is used in php.ini to configure the global memory limit.

Memory limit policy - create policy step 1

The second step of the policy setup is to configure the constraints which determine if the policy applies. Be sure to enable some Memory Limit Policy sub-modules which provide some constraint methods, or you can create your own. If you don’t configure any constraints, the policy will always apply. If that is really what you want, using a module will likely not be the best choice and updating the PHP configuration globally will probably be preferable.

Memory limit policy - create policy step 2

Each constraint will come with its own configuration form. It is possible to negate the constraint. For example, if you need to increase the memory on all frontend pages but not on the admin ones, it can be achieved by using the “Path” constraint with “/admin/” and the negate option. In our example, we will use the “Path” constraint and enter “/sites/default/files/styles/” as the path.

Memory limit policy - create policy step 3

Memory limit policy - create policy step 3 bis

Finally, click the “Finish” button to get the constraints saved. The policy is now listed.

Memory limit policy - list policies 2

All policies listed will be evaluated. In some situations, it may be needed to order the policies using drag & drop.

For some complex cases, it may be difficult to evaluate if a policy applies. To validate a policy is applied, we can use the settings to add the memory information in the headers. The settings can be set in Configuration > Performance > Memory Limit Policy > Configuration (/admin/config/performance/memory-limit-policy/settings).

If no policy applies, headers will only indicate the default memory limit.

Memory limit policy - Headers

If a policy applies, headers will indicate the name of the policy and the new memory limit applied.

Memory limit policy - Headers 2

Finally, export the configuration and push to your version control.

id: image_style label: 'Image style' weight: null status: true memory: 256M langcode: en policy_constraints: - id: path negate: false paths: '/sites/default/files/styles/*' dependencies:

The existing Memory Limit Policy sub-modules already cover a large variety of situation and fine-tuning the memory limit to fit each situation should not be an issue with the module. A future article will describe how to create a custom plugin to override the memory limit in a very specific case.

Источник

Оцените статью