This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Calling PHP from Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calling PHP from Servlet" Watch "Calling PHP from Servlet" New topic
Author

Calling PHP from Servlet

Mohammad Ali
Greenhorn

Joined: Jan 03, 2006
Posts: 11
Please guide me how to call PHP file from a servlet. I found php code which can create file on my server directory. But i want to call that php code from my servlet. Php code is in the php file named UpLoad_File.php
I also want to pass the file name as a parameter to php file. Also is it possible after executing PHP code the control return back to servlet.. is that possible...Thanks
Mohammad Ali
Greenhorn

Joined: Jan 03, 2006
Posts: 11
please guide me how to call PHP code from a servlet... thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

I'm sure it can be done -- anything's possible with enough work. The question is whether it should be done, and I'm going to argue that the answer is "no". To call this PHP code, you're presumably going to have to recreate the PHP server environment (which would mean setting environment variables in a script) then use Java's Runtime.exec() method to execute the PHP interpreter from that script, and then recover the input and output streams and communicate back and forth with that process. That seems like a lot of work -- not to mention a slow, inefficient, and fragile way to do things. Why not just use a standard Java file-upload component?


[Jess in Action][AskingGoodQuestions]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
I recently found this discussion on integrating PHP with Java servlets.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling PHP from Servlet
 
Similar Threads
Getting Resin to ignore PHP script so that webserver deals with request
Using AJAX to send a request to a remote php file
Send requsts to a php file using AJAX
calling html and jsp from Servlet
Want to call Servlet and PHP from oracle