Saturday, 15 September 2012

Increase memory for PHP scripts in MAMP


I'd like to increase the amount of memory allocated to PHP scripts because my optimized script still keeps running out of memory when using MAMP.


If you find that a local PHP script is not executing because it is running out of memory, you can give more memory to PHP scripts by editing the php.ini file(s) in MAMP by the following steps:

  • Stop MAMP servers
  • Open the file /Applications/MAMP/bin/php/php[version]/conf/php.ini (where [version] is the PHP version you're using, e.g. php5.3.6)
  • Search for "memory_limit" (without the quotes). You should end up with something like "memory_limit = 8M"
  • increase the number to however much you will be allocating to your scripts. For example, a 128MB maximum script would need a setting "memory_limit = 128M"
  • restart MAMP servers


This trick is useful for locally-run scripts. For scripts that will be hosted on an external server, you should be careful to match the memory limit of your remote host machine as scripts that will execute in the higher local memory limit may break when deployed online. Not to mention that it is also a useful exercise to think up ways to execute scripts more efficiently.

This was tested on MAMP 2.0.5. Other versions may keep php.ini in a different location.

No comments:

Post a Comment