By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,612 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

Call Java Program in PHP

madzman23
P: 3
Hi guyz, I kinda new here and I dont know if there is post that similar to my question, because I really needed immediately I am posting my question.

Can anyone here help me how to call a Java Program using the PHP.
The PHP code should call a Java program that will extract all the data from the database, I know we can do this in PHP, but I want a more secure one so I want to make a prototype that will call the Java Program that get all the database from the database and make it available for download to the user. I have all my codes done but my last problem is I cant call my Java program even using the exec() and shell_exec() functions. Or I might do it wrong?

Here is my code to call the java program:
I already compiled the program.

Expand|Select|Wrap|Line Numbers
  1. exec("java JavaProgram");
But it doesn't work, I also try to call the firefox to try if I can execute the firefox using the PHP exec() function but it also dont work.
Im using LAMP.

I will gladly appreciate any response from you guyz, I really need your help with this.

Thank you.
Oct 14 '08 #1
Share this Question
Share on Google+
5 Replies


Dormilich
Expert Mod 5K+
P: 8,639
question, what makes the java DB access more sequre than a PHP DB access (once you have secured the sql input)?
Oct 14 '08 #2

Atli
Expert 5K+
P: 5,058
Hi.

I would also have to question that. What makes your Java application more secure than a it's PHP equivalent?

But... in any case.

Can you execute that command in a command line?
Meaning; does this work outside PHP or is it only failing from withing PHP?

Could it be that you need to set an absolute path, rather than just the file name?
Like say "Java /path/to/Java/application"
Oct 14 '08 #3

madzman23
P: 3
Yeah, I did it on the command line. I have been able to run the application in the line. Do you guyz know some other function that I can use to call and execute a program using PHP?

Well, as I know it Java is more secured than PHP base on the server side programming. And I am really have no choice but to do it because my new project requires to have that and I will like to really know if its feasible to have it that way.
I want to ask you guyz if you make a project similar to this because I am new in PHP. Well, if you guyz dont think its feasible, well I think my prototype is a failure.
Oct 15 '08 #4

Atli
Expert 5K+
P: 5,058
Yeah, I did it on the command line. I have been able to run the application in the line. Do you guyz know some other function that I can use to call and execute a program using PHP?
The exec functions do work for this sort of thing.
You just need to figure out what is causing this problem.

If you are sure the paths are correct, could it be that the user running PHP does not have permission to execute the file?

Try using chmod to change the file permission. Something like:
Expand|Select|Wrap|Line Numbers
  1. $ chmod 755 /path/to/file.ext
You could also look into the PHP / JAVA Integration extension, but I have no experience with that so I can't really say how well that works.
Well, as I know it Java is more secured than PHP base on the server side programming..
That makes absolutely no sense.

The only reason I can think of why a Java program may be considerd safer is that Java is compiled, while PHP is interpreted.
Meaning that the PHP source code is read every time the program is executed, while the Java code is only read once, after which the complied binary files are used.

But none of that matters on a typical web server, because the PHP code itself will never be accessible to the public. Only the output of the PHP code will be.
And in any case. If you are worried about that you could always just put sensitive scripts outside the web-root and include them into your public scripts.
Oct 15 '08 #5

madzman23
P: 3
Okay, thanks for that explanation bro.

I think the PHP/Java Integration is not necessary because I just need to run the Java program, so I will not need any variables or function that are in Java. Its just like I am calling an executable program like Firefox, C++ executable files, etc. and afterwards continue my php script.
Oct 15 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.