PHP integrates with existing Java applications

Source: Internet
Author: User
Tags ini php script
Another advantage of the program PHP feature is its ability to invoke existing Java object methods. This feature allows you to integrate PHP into existing java-based applications. This feature is especially fashionable if you are promoting PHP in your workplace. "Java is everywhere." ”





To implement this feature, you need to install the Java Virtual Machine (JVM) on the server. If you will install (or have installed) JDK from Sun, Kaffe, IBM or Blackdown, you can start working quickly.



When configuring PHP, you need to add--with-java parameters to the configuration directive, and then modify some elements in the php.ini file. The following lines are typically modified in php.ini:



[Java]

Java.library.path=/path/to/library

java.class.path=/classpath/

Extension_dir=/path/to/extensions

Extension=libphp_java.so



It is necessary to remind you that the above changes depend on your installation type. You should read the Readme file in the Ext/java directory under your PHP installation directory to learn more about the Java feature configuration.



Here's a simple example: Create a new Java object from a PHP script. The script then accesses some of the Java properties and outputs them. This is as exciting as the example of COM, but it also gives you an idea of more possible ways.

?



$system = new Java ("Java.lang.System");

echo "<p>java Version =". $system->getproperty ("Java.version"). "<br>";

echo "Java vendor =". $system->getproperty ("Java.vendor"). "</p>";



?>



If you already have Java knowledge, you should do your best to help developers on this project. Such integration capabilities will inevitably be the key to future PHP development and acceptance. Therefore, the more people do these things, the future development of PHP will be more beautiful.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.