Categories
troubleshooting wordpress

PHP command line memory limit

PHP Fatal error:  Allowed memory size of 987654 bytes exhausted (tried to allocate 321 bytes) in /path/to/file.php on line 12
Error: There has been a critical error on this website. 

If you get an out of memory error when running a PHP file from the CLI, you can inline an increased limit for just a single run with the -d memory_limit switch.

Examples:

# For calling a PHP file directly
php -d memory_limit=512M file.php

# For running a WP CLI command
php -d memory_limit=512M "$(which wp)" search-replace 'find' 'replace' --report-changed-only

By bo.

I'm @boyEatsSteak in a lot of places. I have been wanting 🍕 for weeks. I like gadgets and technology and keeping notes and tips for my future self since all I can remember is that I forget things.