Get memory error when running java command via PHP script


#1

I am trying to run Java through PHP script using exec or shell_exec, however, I get error. Here is the scenario:

I can ssh into my account and run Java just fine. As a test:

(running as user XYZ)

java -version

prints:

java version "1.6.0_07"
Java™ SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot™ 64-Bit Server VM (build 10.0-b23, mixed mode)

Happy, no errors.

I can even run large API (Lucene) without error.

HOWEVER,

when run same command in PHP script, it outputs an error:

exec(‘java -version’):

Could not reserve enough space for object heap

shell_exec(‘java -version’):

Error occurred during initialization of VM
Could not reserve enough space for object heap

I have run whoami command from PHP script, and it shows that exec and shell_exec are running command as the same user (XYZ):

exec(‘whoami’)
shell_exec(‘whoami’)

both output: XYZ (same user used in successful ssh test)

Is this really a memory problem? Can it be a server configuration issue? Because I can run the same command ssh, and java works fine (no memory issue)

RECAP:

Run java command ssh, works fine. Run SAME java command from PHP script, as SAME user, and I get error.

Any help with this issue would be very much appreciated.

Allasso


#2

Yep, your java prog probably uses 95% of your RAM allowance. Running a PHP script probably takes 6%. Together, too much RAM usage.


#3

how do I determine how much is my RAM allowance?

[hr]
BTW, my java “program” is -version.
And my PHP script is <?php shell_exec('java -version'); ?>
[hr]
If I run php script through ssh on command line, it works:

php -f test_file.php

outputs:

Java™ SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot™ 64-Bit Server VM (build 10.0-b23, mixed mode)
java version "1.6.0_07"
Java™ SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot™ 64-Bit Server VM (build 10.0-b23, mixed mode)


#4

I’m interested in this “RAM allowance” too, and how you can determine it.