PHP CLI increase memory limit

PHP logo

When running a PHP script from command line interface (CLI), a higher memory limit may be required in order for the script to be successfully executed. This can be achieved using the “-d” or “–define” option in the command. According to the manual:

This option allows you to set a custom value for any of the configuration directives allowed in php.ini.

An example of running a PHP script in CLI with custom memory limit:

php -d memory_limit=128M my_script.php

Of course the “-d” or “–define” option is not limited to the memory limit directive; it can be use to alter other php.ini directives as well.

About Cristian Radulescu

PHP // MySql // Linux // Android
This entry was posted in Linux, PHP, Programming, Windows and tagged , , . Bookmark the permalink.

4 Responses to PHP CLI increase memory limit

  1. james says:

    Life Saver!!!!

    I wish more people had a knack for writing things in a few short and sweet sentences.

  2. Pingback: Yii and PHP:: Executed command line and memory limit « Kongsi-Kongsi

  3. szako says:

    Thanks, was getting a headache already :-)

  4. iroybot says:

    or you can use -d memory_limit=-1 to unlimit the restriction.

Leave a Reply