Call Java Program in PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madzman23
    New Member
    • Oct 2008
    • 3

    Call Java Program in PHP

    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.

    Code:
    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.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    question, what makes the java DB access more sequre than a PHP DB access (once you have secured the sql input)?

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      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"

      Comment

      • madzman23
        New Member
        • Oct 2008
        • 3

        #4
        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.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Originally posted by madzman23
          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:
          Code:
          $ 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.
          Originally posted by madzman23
          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.

          Comment

          • madzman23
            New Member
            • Oct 2008
            • 3

            #6
            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.

            Comment

            Working...