Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory exhausted (minimal script)

Tags:

php

This is something that has never happened to me before.

I receive Allowed memory size of X bytes exhausted but my script hardly uses any memory.

I created a small test script, with minimal code, and it still fails!

$ cat x.php
#!/usr/bin/env php
<?php

function ha($msg) {

}

ha("Hi");

$ ./x.php

Fatal error: Allowed memory size of 62914560 bytes exhausted (tried to allocate 1081028648 bytes) in x.php on line 4

Interestingly if I remove the $msg parameter of the function it does not emit a warning. As said, I never had this happen before. The php.ini is normal too.

System information:

$ php -v
PHP 5.6.19 (cli) (built: Jun 22 2016 20:13:44)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
$ php -m
[PHP Modules]
bcmath
calendar
Core
ctype
date
dom
ereg
exif
filter
gd
hash
json
libxml
mbstring
openssl
pcntl
pcre
PDO
pdo_sqlite
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]
$ df -h
Filesystem                Size      Used Available Use% Mounted on
ubi0:rootfs             362.9M    122.2M    240.7M  34% /
tmpfs                    40.0K         0     40.0K   0% /mnt/.splash
none                      1.0M    116.0K    908.0K  11% /dev
/dev/sda1                56.8G      5.4G     48.5G  10% /media/sda1
tmpfs                    50.0M     72.0K     49.9M   0% /var/volatile
tmpfs                   123.9M         0    123.9M   0% /dev/shm
tmpfs                    20.0M         0     20.0M   0% /media/ram
$ cat /proc/meminfo
MemTotal:         253712 kB
MemFree:          179720 kB
like image 537
marco-a Avatar asked Apr 12 '19 18:04

marco-a


People also ask

How do I fix memory size exhausted?

You can find the php. ini file in the public_html for your website and right-click on the file to Edit it. Look for the line defining the memory_limit variable and set the value accordingly. Then, save the changes and reload your site to see if the PHP “Allowed Memory Size of Bytes Exhausted” error has been resolved.

How do I fix PHP fatal error allowed memory size 134217728 bytes exhausted?

Change the memory limit in the php. ini file and restart Apache. After the restart, run the phpinfo(); function from any PHP file for a memory_limit change confirmation. Memory limit -1 means there is no memory limit set.


1 Answers

Wow I never thought that I would actually encounter something like this.

The reason this happened is because a bit (!!) got flipped in the binary.

I replaced the binary with a fresh one and it worked again.

Here's the difference of the two binaries:

enter image description here

like image 67
marco-a Avatar answered Sep 23 '22 23:09

marco-a