0

Is there a way to run php server**(remote)** scripts from a java program (with secured/encrypted connection).

Adi
  • 1,263
  • 1
  • 13
  • 24

5 Answers5

3

Visit (make post or get HTTP request) php page from your java program, for example, via HttpUrlConnection type

Victor Sorokin
  • 11,878
  • 2
  • 35
  • 51
1

Make sure to use HTTPS (not HTTP) if you want a secure connection.

The server will need to support ssl for that, if you're using Apache, make sure you have mod_ssl

Jeffrey Aylesworth
  • 8,242
  • 9
  • 40
  • 57
1

Try Caucho Quercus, Java implementation of PHP. I have tried, very good indeed.
http://quercus.caucho.com/

Quercus is Caucho Technology's 100% Java implementation of PHP 5 released under the Open Source GPL license. Quercus comes with many PHP modules and extensions like PDF, PDO, MySQL, and JSON. Quercus allows for tight integration of Java services with PHP scripts, so using PHP with JMS or Grails is a quick and painless endeavor.

With Quercus, PHP applications automatically take advantage of Java application server features just as connection pooling and clustered sessions.

Quercus implements PHP 5 and a growing list of PHP extensions including APC, iconv, GD, gettext, JSON, MySQL, Oracle, PDF, and Postgres. Many popular PHP application will run as well as, if not better, than the standard PHP interpreter straight out of the box. The growing list of PHP software certified running on Quercus includes DokuWiki, Drupal, Gallery2, Joomla, Mambo, Mantis, MediaWiki, Phorum, phpBB, phpMyAdmin, PHP-Nuke, Wordpress and XOOPS.

Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
0

If scripts are not web accessible then you can connect to a remote server via SSH (using SSHTools for example) and run scripts from shell (php scriptfile.php).

serg
  • 109,619
  • 77
  • 317
  • 330
0

Check output of myfile.php in java (might work):

Runtime rt = Runtime.getRuntime();
String[] commands = {"wget","external_src_url.com/myfile.php","&&""php", "myfile.php",};
Process proc = rt.exec(commands);

BufferedReader stdInput = new BufferedReader(new 
     InputStreamReader(proc.getInputStream()));

BufferedReader stdError = new BufferedReader(new 
     InputStreamReader(proc.getErrorStream()));
String s = null;
while ((s = stdInput.readLine()) != null) {
    System.out.println(s);
}
while ((s = stdError.readLine()) != null) {
    System.out.println(s);
}

Uses @senthil's answer on Java Runtime.getRuntime(): getting output from executing a command line program.