2

When I make a command in PHP like:

exec('java -version > test.txt');

the file test.txt is created but with an error inside :

There is insufficient memory for the Java Runtime Environment to continue.

Native memory allocation (mmap) failed to map 2555904 bytes for committing reserved memory.

An error report file with more information is saved as: /tmp/hs_err_pid25505.log

The error report file does not exist at this location.

When I try to execute the same command in the shell window, it works:

openjdk version "1.8.0_101"

OpenJDK Runtime Environment (build 1.8.0_101-b13) OpenJDK 64-Bit Server VM (build 25.101-b13, mixed mode)

The command i'm trying to execute is actually not java -version but a more complicated one. However, the result is the same.

I think the problem comes from PHP. Until now I have tried to increase memory_limit but to no avail. I've seen people having similar problems but the solutions proposed don't work.

Vic
  • 21,473
  • 11
  • 76
  • 97
Ixtle
  • 21
  • 3

2 Answers2

0

Set the memory Xms and Xmx options to java. I am not a php guy I have shared some links for php also, just verify if you are setting both the options.

See if you can fork the process execution of java to independent thread and wait

What are the Xms and Xmx parameters when starting JVMs?

PHP : settings memory_limits > 1024M does not work

ini_set("memory_limit") in PHP 5.3.3 is not working at all

Community
  • 1
  • 1
jan_kiran
  • 301
  • 3
  • 16
  • Hello, thanks for answering. I have already tried to specify limits with -Xmx2G and -Xms2G but it does not change anything... After reading your links I verified in phpinfo.php that memory_limit is as I wrote it in php.ini, at 4G. I don't think the problem lies here. – Ixtle Aug 29 '16 at 11:08
  • had to disable MPROTECT on the java binary. You can use the paxctl utility for this: paxctl -m /usr/lib/jvm/java-7-openjdk/jre/bin/java check this link if it helps http://stackoverflow.com/questions/27262629/jvm-cant-map-reserved-memory-when-running-in-docker-container You'll need to do paxctl -c on the binary first if you've never used it on that binary before: paxctl -c /usr/lib/jvm/java-7-openjdk/jre/bin/java – jan_kiran Aug 29 '16 at 12:26
  • But I think MPROTECT only exists on **Debian**. I'm on **CentOS**. Moreover typing _paxctl_ returns _command not found_. – Ixtle Aug 29 '16 at 12:45
0

The JVM never really runs out of memory. It does memory computation of the heap stack in advance.

The Structure of the JVM, Chapter 3, section 3.5.2 states:

  • If Java virtual machine stacks can be dynamically expanded, and expansion is attempted but insufficient memory can be made available to effect the expansion, or if insufficient memory can be made available to create the initial Java virtual machine stack for a new thread, the Java virtual machine throws an OutOfMemoryError.

For Heap, Section 3.5.3.

  • If a computation requires more heap than can be made available by the automatic storage management system, the Java virtual machine throws an OutOfMemoryError.

It looks like you're hitting the maximum memory limit: Java is asking for much more than the PHP(/apache!) is providing and cannot get it. Strange it's not that much, but most probably doens't include the JRE image itself so it will be much more.

Check and/or rise the PHP memory limit (/etc/php.ini), something like :

memory_limit = 128M

Depending on the configuration you could do it also in the .php itself:

ini_set('memory_limit', '128M');

In case posting the /tmp/hs_err_pid25505.log the error is referring to would be very helpful as well!

U.Swap
  • 1,921
  • 4
  • 23
  • 41
  • Hello, thank you for your answer. However I already set memory_limit to 3G in php.ini... And the error log is not generated ; I can't find it at the specified location. – Ixtle Aug 29 '16 at 10:26