php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48809 "virtual memory exhausted: Cannot allocate memory" with libmagic/apprentice.c
Submitted: 2009-07-05 19:05 UTC Modified: 2009-07-05 22:49 UTC
Votes:43
Avg. Score:4.2 ± 1.1
Reproduced:41 of 42 (97.6%)
Same Version:17 (41.5%)
Same OS:5 (12.2%)
From: ibboard at gmail dot com Assigned:
Status: Wont fix Package: Compile Failure
PHP Version: 5.3.0 OS: CentOS 4
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-07-05 19:05 UTC] ibboard at gmail dot com
Description:
------------
I'm trying to compile PHP 5.3 on a VPS with 256MB of memory, but I keep getting "out of memory" errors before 'make' completes. I've compiled 5.2.x on the VPS before and I've freed up over 170MB of my 256MB of memory, but still I get the following error (always the same file):

virtual memory exhausted: Cannot allocate memory
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

My host temporarily bumped my account up to 512MB of memory, but it still took all of the free memory before failing (350MB+). Disabling the extension that the file is from with "--disable-fileinfo" gets me beyond the error and continues without running out of memory (until it hits a different error in libgd, which I'm looking in to).

May be similar to http://bugs.php.net/bug.php?id=48593, but crashes out with insufficient memory rather than hanging indefinitely.

Reproduce code:
---------------
$ wget http://uk2.php.net/get/php-5.3.0.tar.bz2/from/this/mirror
$ tar -xjvf php-5.3.0.tar.bz2
$ cd php-5.3.0
$ ./configure --prefix=/usr/local/php5-fcgi --with-kerberos=/opt --with-layout=GNU --with-regex=php --with-gettext --enable-mbstring --enable-libxml --with-pcre-regex=/opt --with-imap=shared --with-imap-ssl --with-mysql=shared,/opt --with-mysqli=shared,/usr/bin/mysql_config --with-mysql-sock=/var/lib/mysql/mysql.sock --with-libxml-dir=/opt --enable-gd-native-ttf --with-gd=/opt --with-jpeg-dir=/opt --with-freetype-dir=/opt --with-mcrypt --with-zlib-dir=/opt --with-png-dir=/opt --with-config-file-scan-dir=/usr/local/etc/php.d
$ make

Expected result:
----------------
PHP compile to complete so that I can run "sudo make install".

Actual result:
--------------
[lots of compile output]
...
/bin/sh /home/ibb_admin/temp/php-5.3.0/libtool --silent --preserve-dup-deps --mode=compile gcc -I/home/ibb_admin/temp/php-5.3.0/ext/fileinfo/libmagic -Iext/fileinfo/ -I/home/ibb_admin/temp/php-5.3.0/ext/fileinfo/ -DPHP_ATOM_INC -I/home/ibb_admin/temp/php-5.3.0/include -I/home/ibb_admin/temp/php-5.3.0/main -I/home/ibb_admin/temp/php-5.3.0 -I/home/ibb_admin/temp/php-5.3.0/ext/date/lib -I/home/ibb_admin/temp/php-5.3.0/ext/ereg/regex -I/usr/include/libxml2 -I/opt/include -I/opt/include/freetype2 -I/usr/include/imap -I/usr/kerberos/include -I/home/ibb_admin/temp/php-5.3.0/ext/mbstring/oniguruma -I/home/ibb_admin/temp/php-5.3.0/ext/mbstring/libmbfl -I/home/ibb_admin/temp/php-5.3.0/ext/mbstring/libmbfl/mbfl -I/opt/include/mysql -I/usr/include/mysql -I/home/ibb_admin/temp/php-5.3.0/ext/sqlite3/libsqlite -I/home/ibb_admin/temp/php-5.3.0/TSRM -I/home/ibb_admin/temp/php-5.3.0/Zend    -I/usr/include -g -O2  -c /home/ibb_admin/temp/php-5.3.0/ext/fileinfo/libmagic/apprentice.c -o ext/fileinfo/libmagic/apprentice.lo 
virtual memory exhausted: Cannot allocate memory
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-05 19:08 UTC] rasmus@php.net
We know that file takes quite a bit of memory to compile on older versions of gcc.  It should be better in newer versions though.  Not much we can do about this.  We aren't going to change perfectly valid code just because some older compilers have trouble with it.
 [2009-07-05 19:24 UTC] ibboard at gmail dot com
"Quite a bit" of memory? That seems like a bit of an understatement when it will quite happily consume over 350MB of memory on a single file and previous versions of PHP could be compiled in ~150MB or less (albeit without that extension) :D

Maybe libmagic needs disabling as a default module if it was in PECL before and is known to causes problems with older compilers?

How much memory am I expected to need to compile it if it fails with 350MB? I've just watched 'top' while the compile continued and it maxed out at ~120MB without libmagic, which is far more reasonable.
 [2009-07-05 21:48 UTC] rasmus@php.net
It is probably up in the 600-700M range.  If you are using an older toolchain in a severely memory-starved environment, you shouldn't expect to be able to compile everything there.  Why not simply cross-compile from a real dev box somewhere and copy the binaries over?  You can install your production OS in a vm slice on whatever home machine you have and compile there.  
 [2009-07-05 22:46 UTC] scottmac@php.net
What version of gcc were you using?

It would be nice to track this where possible.
 [2009-07-05 22:49 UTC] scottmac@php.net
What version of gcc were you using?

It would be nice to track this where possible.
 [2010-06-21 22:32 UTC] mackeul at gmail dot com
Ran into the same problem with GCC 3.4.5 on a "2.6.9-34.EL #1 Fri Feb 24 16:44:51 EST 2006 i686 i686 i386 GNU/Linux" machine 
with 256MB of memory.
 [2010-11-16 08:52 UTC] info at fedushin dot ru
Adding --disable-fileinfo to ./configure solves the problem.
 [2013-05-27 15:01 UTC] hawkdoom at mail dot ru
Проблема особенно силно проявляется на выделенных серверах с обрезанием оперативы в тарифе, ща попробую решение предыдущего автора
 [2013-05-27 15:30 UTC] hawkdoom at mail dot ru
Ни хрена не помогло
 [2015-12-22 15:07 UTC] noreplythanks at example dot fake dot com
I had this issue too, on Raspbian (Linux) on a Raspberry Pi.
It ran out of memory, even though no other applications were using much
memory. It just displays a chunk of text to do with installing and then
does nothing (whilst the memory it is using increases to "breaking point" as shown in Task Manager), then something kicks in and kills it and it exits with an error:

"virtual memory exhausted: Cannot allocate memory
Makefile:742: recipe for target ext/fileinfo/libmagic/apprentice.lo failed
make:  *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
 [2016-05-08 20:07 UTC] no-reply-thanks at fake-url dot example dot com
Like "info at fedushin dot ru" states, adding --disable-fileinfo to ./configure "solves" the problem (I don't know if it has any negative effects though).
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC