"php --help" results in "PHP memory exhausted" error on Ubuntu

13,734

Solution 1

Check the php.ini file for PHP CLI (/etc/php5/cli/php.ini).

Make sure the memory_limit declaration has its units set:

memory_limit = 32M

not

memory_limit = 32

It fixed it for me. I hope it works for you too.

Solution 2

I am assuming you're on a recent Linux install. I'm using Ubuntu, but any Debian like Linux distribution will be similar and other distribution won't have a lot of differences either.

In /etc/php5/ I have the following configuration directories:

root@delphic:/etc/php5# ls -la
total 20
drwxr-xr-x  5 root root 4096 2011-01-15 00:52 .
drwxr-xr-x 92 root root 4096 2011-01-15 00:51 ..
drwxr-xr-x  2 root root 4096 2011-01-05 10:55 apache2
drwxr-xr-x  2 root root 4096 2011-01-15 00:52 cli
drwxr-xr-x  2 root root 4096 2011-01-15 00:51 conf.d
root@delphic:/etc/php5# cd cli
root@delphic:/etc/php5/cli# ls -al
total 76
drwxr-xr-x 2 root root  4096 2011-01-15 00:52 .
drwxr-xr-x 5 root root  4096 2011-01-15 00:52 ..
lrwxrwxrwx 1 root root     9 2011-01-15 00:52 conf.d -> ../conf.d
-rw-r--r-- 1 root root 67457 2011-01-12 19:51 php.ini 
root@delphic:/etc/php5/cli# grep memory php.ini 
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = -1

Are you sure you changed the CLI memory limit as well?

If you're on a shared hosting service, you will have to ask their support for help on changing the limits or have them find out why php is consuming so much memory even on the command line.

Solution 3

The text

Allowed memory size of 262144

Suggests that PHP doesn't think it's memory limit is 128MB. Perhaps you've missed some php.ini file? Could you maybe post your php.ini online?

Solution 4

What a strange thing the instructions on the ini say to use MB but that wouldn't work for me, standard apt-get install, only other bit I added was APC. I couldn't figure what could be wrong, thankfully some comments above suggested just using the M

Seems like a bug IMO, especially given the instructions on the ini.

ini says this //Maximum amount of memory a script may consume (128MB)

But only this worked for me :/ 228M

Solution 5

The value in my php.ini file had 1024MB and I was still getting the error. What I did to fix was changing it to 1024M, strange as the example text said 128MB

Share:
13,734
Admin
Author by

Admin

Updated on June 09, 2022

Comments

  • Admin
    Admin almost 2 years

    PHP Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 523800 bytes) in Unknown on line 0

    Same thing occurs with "php5 --help"

    I have already researched this and read that I should: 1) increase the memory limit in php.ini - it's at 128MB in all instances of php.ini - should be enough to run php cli help 2) make the script more memory efficient - obviously doesn't apply to --help

    Please help if you can ?