www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] Detect JRE in server using PHP

  1. #1
    Join Date
    Jun 2007
    Location
    Tangerang, Banten
    Posts
    258

    resolved [RESOLVED] Detect JRE in server using PHP

    Can php detect if webserver has installed JRE or not?

    thanks,
    Andre

  2. #2
    Join Date
    Jun 2007
    Location
    Tangerang, Banten
    Posts
    258

    resolved

    I think i know the answer..
    The solution : call program java -version.
    This assume that i not install php-java extension.
    If the JRE is exists, then it will print the java version.
    Otherwise, it will output program not found.

    This works in my Ubuntu 7.10
    PHP Code:
    $command "java -version 2>&1";
    exec($command,$output);
    print_r($output); 
    It will output :
    Array
    (
    [0] => java version "1.6.0_03"
    [1] => Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
    [2] => Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)
    )
    Why we can not just write it "java -version"?
    Because :
    Quote Originally Posted by Rob Prime on [url
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=1&t=021218][/url]
    java -version writes to the error stream, not the output stream.
    So, how we can catch error messages when calling exec?
    For full answer, visit : http://id2.php.net/manual/en/function.exec.php#35917

    To find the exact version of JRE, just use regex on $output[0] variable.
    Then, solved!!

  3. #3
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    the only problem is that this approach is dependent on having the java executable on the path of the user executing your PHP script. right now you're running on ubuntu so more likely than not, PHP is running as you. however, in production servers PHP will likely be executed as 'nobody' meaning java has to be on nobody's path.

  4. #4
    Join Date
    Jun 2007
    Location
    Tangerang, Banten
    Posts
    258
    Quote Originally Posted by chazzy
    the only problem is that this approach is dependent on having the java executable on the path of the user executing your PHP script. right now you're running on ubuntu so more likely than not, PHP is running as you. however, in production servers PHP will likely be executed as 'nobody' meaning java has to be on nobody's path.
    Aaa....
    You are right!! Absolutely right!!
    So then, it down again..
    You have better approach or technique??
    Please help, and thanks for your precious information...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles