php exec() for java on website doesn't work but works in server terminal -
i have vps (linux server) downloaded 64-bit version of java. on terminal, able run commands such as:
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64/jre/bin/java -version and receive following output:
openjdk version "1.8.0_65" openjdk runtime environment (build 1.8.0_65-b17) openjdk 64-bit server vm (build 25.65-b01, mixed so test website, used following php:
<?php $output = array(); exec('/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64/jre/bin/java -version', $output); foreach($output $line) { echo $line; echo '<br/>'; } ?> but receive following error:
error occurred during initialization of vm not allocate metaspace: 1073741824 bytes so far have tried following:
1) i've updated permissions on java that:
stat -c "%a %n" /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64/jre/bin/java returns:
755 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64/jre/bin/java 2) i've turned php safe-mode off
3) i've changed max memory in php.ini file 1.5gb
what causes error , how java program run without error?
i able reproduce error using bluehost's webspace, , fix it.
i running heavy java program though php method: shell_exec , java produced error:
error occurred during initialization of vm not allocate metaspace: 1073741824 byte linux version:
uname -a linux box1.bluehost.com 1.2.50-39.elk6.x86_64 #1 smp mon nov 2 03:10:26 cst 2015 x86_64 x86_64 x86_64 gnu/linux php version:
php --version php 5.4.43 (cgi-fcgi) (built: jul 13 2015 15:00:01) zend engine v2.4.0, copyright (c) 1998-2014 zend technologies zend guard loader v3.3, copyright (c) 1998-2013, zend technologies java version:
java -version java version "1.8.0_71" reproduce problem:
make test.php script under public_html, this:
<?php shell_exec('java hungryjavaprogram > /home/user/mylog.log'); ?> the java program called hungryjavaprogram allocates gigabyte of memory.
from browser, visit yoursite.com/test.php run php file. java program reports:
error occurred during initialization of vm not allocate metaspace: 1073741824 byte why happening?
the java program has requested more memory php has authorized.
solution #1, increase memory available:
find out how memory php has authorized programs running inside shell_exec can consume making php script , visiting in browser:
<?php phpinfo(); ?> look at: memory_limit see default is: 128m
find php.ini under public_html , find memory_limit variable , set 2048m. on bluehost changes take effect immediately. understand 1 rogue program might bring down server. keep low possible.
workaround solution #2, use php fastcgi.
in public_html directory in .htaccess file, saw this:
addhandler application/x-httpd-php54 .php comment out , replace this:
addhandler fcgid54-script .php and java program runs without error. though memory limit remains @ 128m, php doesn't seem enforce limit on java programs running within shell_exec("java myprogram").
Comments
Post a Comment