To increase the PHP memory limit for all PHP CLI (Command Line Interface) commands in Drupal, you can add a configuration to the settings.php
file. Here's how to do it:
-
Open the
settings.php
file for your Drupal installation. This file is usually located in thesites/default
folder of your Drupal installation. -
Add the following lines of code to the bottom of the
settings.php
file:/** * Set PHP memory limit for CLI commands. */ if (PHP_SAPI === 'cli' || ) { ini_set('memory_limit', -1); ini_set('max_execution_time', -1); // You can do this or change any other global variables here. }
This code checks if the current script is being executed in CLI mode by using the
php_sapi_name()
function. If it is being executed in CLI mode, it sets the PHP memory limit to -1 or infinite. -
Save the
settings.php
file.
Now, whenever you run a PHP CLI command, the PHP memory limit will be set to -1. You can adjust the memory limit value by changing the value passed to the ini_set()
function. Instead of the PHP_SAPI php constant, you can also use the function `php_sapi_name()`.