Blog

Increase PHP Memory Limit when using Laravel Herd

Laravel

Since the release, I have been a user of Laravel Herd. Previously, I used Laravel Valet, but Herd (in combination with dbngin) simplifies the deployment of a Laravel development environment on macOS even further.

However, when first running pestphp tests, I encountered a problem:

php artisan test -p

led to the following error message:

  .....................................................
In WorkerCrashedException.php line 41:
                                                                                                                                                                         
  The test "PARATEST='1' TEST_TOKEN='10' UNIQUE_TEST_TOKEN='10_64c267b53c4d2' /Users/sebastian/dev/my_project/tests/Feature/ArchTest.php" failed.                              
                                                                                                                                                                         
  Exit Code: 255(Unknown error)                                                                                                                                          
                                                                                                                                                                         
  Working directory: /Users/sebastian/dev/my_project                                                                                                                           
                                                                                                                                                                         
  Output:                                                                                                                                                                
  ================                                                                                                                                                       
                                                                                                                                                                         
  Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /Users/sebastian/dev/my_project/vendor/nikic/php-parser/lib/PhpParser/Lexe  
  r.php on line 319                                                                                                                                                      
                                                                                                                                                                         
  Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in /Users/sebastian/dev/my_project/vendor/pestphp/pest/src/Plugins/Actions/Ca  
  llsShutdown.php on line 1                                                                                                                                              
                                                                                                                                                                         
                                                                                                                                                                         
  Error Output:                                                                                                                                                          
  ================                                                                                                                                                       
                                                                                                                                                                         

paratest [--functional] [-m|--max-batch-size MAX-BATCH-SIZE] [--no-test-tokens] [--passthru-php PASSTHRU-PHP] [-p|--processes PROCESSES] [--runner RUNNER] [--tmp-dir TMP-DIR] [-v|--verbose] [--bootstrap BOOTSTRAP] [-c|--configuration CONFIGURATION] [--no-configuration] [--cache-directory CACHE-DIRECTORY] [--testsuite TESTSUITE] [--exclude-testsuite EXCLUDE-TESTSUITE] [--group GROUP] [--exclude-group EXCLUDE-GROUP] [--filter FILTER] [--process-isolation] [--strict-coverage] [--strict-global-state] [--disallow-test-output] [--dont-report-useless-tests] [--stop-on-defect] [--stop-on-error] [--stop-on-failure] [--stop-on-warning] [--stop-on-risky] [--stop-on-skipped] [--stop-on-incomplete] [--fail-on-incomplete] [--fail-on-risky] [--fail-on-skipped] [--fail-on-warning] [--order-by ORDER-BY] [--random-order-seed RANDOM-ORDER-SEED] [--colors [COLORS]] [--no-progress] [--display-incomplete] [--display-skipped] [--display-deprecations] [--display-errors] [--display-notices] [--display-warnings] [--teamcity] [--testdox] [--log-junit LOG-JUNIT] [--log-teamcity LOG-TEAMCITY] [--coverage-clover COVERAGE-CLOVER] [--coverage-cobertura COVERAGE-COBERTURA] [--coverage-crap4j COVERAGE-CRAP4J] [--coverage-html COVERAGE-HTML] [--coverage-php COVERAGE-PHP] [--coverage-text [COVERAGE-TEXT]] [--coverage-xml COVERAGE-XML] [--coverage-filter COVERAGE-FILTER] [--no-coverage] [--] [<path>]

The cause of the problem is indicated here: "Fatal error: Allowed memory size of 134217728 bytes exhausted". The amount of memory that PHP is allowed to use is insufficient. The problem can be solved quite easily.

  • Click on the menu icon of Herd
  • Click on Show php.ini
  • Open the php.ini in the appearing Finder window
  • Insert the following entry:
memory_limit = 256M

This increases the memory limit from the standard set 128MB to 256MB. The next time I tried to run the tests, everything worked as desired.