• Register
Welcome to phpanswers , where you can ask questions and receive answers from other members of the community.

How can I embed a java programme in PHP file and what changes have to be done in PHP.ini file?

0 votes
asked 2 years ago by Neeraj Narkhede (1,670 points)

1 Answer

0 votes

JAVA and PHP can be integrated in two ways.

  1. embed PHP in JAVA Servlet environment, which is the more stable and efficient solution

    OR
     
  2. integrate JAVA support into PHP

The former is provided by a SAPI module that interfaces with the Servlet server, the latter by this Java extension.
The Java extension provides a simple and effective means for creating and invoking methods on Java objects from PHP. The JVM is created using JNI, and everything runs in-process.

Example Code:

getProperty('java.version') . ''; echo 'Java vendor=' . $system->getProperty('java.vendor') . ''; echo 'OS=' . $system->getProperty('os.name') . ' ' . $system->getProperty('os.version') . ' on ' . $system->getProperty('os.arch') . ' '; // java.util.Date example $formatter = new Java('java.text.SimpleDateFormat', "EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz"); echo $formatter->format(new Java('java.util.Date')); ?>

The behaviour of these functions is affected by settings in php.ini.
Table 1. Java configuration options
Name
Default
Changeable
java.class.path
NULL
PHP_INI_ALL
Name Default Changeable
java.home
NULL
PHP_INI_ALL
java.library.path
NULL
PHP_INI_ALL
java.library
JAVALIB
PHP_INI_ALL

answered 2 years ago by vikramapte (1,980 points)

Related questions