0

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

1
  • 1
    Just a linguistic addendum - if it's remote, then you don't "run" them but "invoke" or "query". Commented Feb 15, 2011 at 18:46

5 Answers 5

3

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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.

Comments

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).

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.