0

I have a system which is implemented using PHP(Joomla). Now the client wants to integrate a SMS gateway. Unfortunately SMS gateway does not supoort PHP. It's written in Java and All the examples are written in JAVA.

I'm supposed to include webservices‐rt.jar to my program and run a example script as below.

lk.mobitel.esms.User user = new lk.mobitel.esms.User (); user.setUsername(“TestUser”);
user.setPassword(“Password”);
lk.mobitel.esms.test.ServiceTest st = new lk.mobitel.esms.test.ServiceTest (); 
System.out.println(st.testService(u));

According to my knowledge I can run a .jar as below using PHP

<?php exec("java -jar filename.jar arguments",$output); ?>

How can I run a JAVA script like above in PHP? Is it possible? Is there a way to bridge PHP and JAVA? What I want is to run JAVA in PHP else I would say communicate between these two.

Techie
  • 42,101
  • 38
  • 144
  • 232
  • Whats wrong with running the JAR as shown? – cowls Feb 19 '13 at 09:24
  • I have an Apache server and PHP system. what I want is to run JAVA in PHP else I would say communicate between these two. – Techie Feb 19 '13 at 09:25
  • You could always read through the Java, work out what it's doing and where it posts to and recreate the post using cURL in PHP? Wireshark is pretty good for capturing HTTP traffic..? Which SMS Gateway are you using? I work for www.txtNation.com and we could help you here! – Marc Feb 19 '13 at 09:26
  • This is a gateway which is selected by client so I have to use this – Techie Feb 20 '13 at 01:52

3 Answers3

0

It's not possible to combine PHP and Java in the same script and have them executed in one run.

Your exec approach is the way to go, if you are approaching from PHP. But you should rather use passthru as exec does not return anything. With passthru you can get the shell response of your java command and act accordingly.

acme
  • 13,318
  • 6
  • 65
  • 102
0

Is there a way to bridge PHP and JAVA? What I want is to run JAVA in PHP else I would say communicate between these two.

Simple answer:

Bridge using data-exchange layer. :)

Hint (in super simple language): My favorite webservice uses PERL to process their scripts and I fetch them using XML. Groupon is made on RoR but, I happily get tweets, thanks to their API which outputs a JSON.

Simple? :)

Karma
  • 4,610
  • 1
  • 32
  • 61
0

I never did this, but PHP Manual gave a link for PHP-Java Bridge for PHP5 as PHP/Java Bridge. If it is what you are looking for ?

kuldeep.kamboj
  • 2,462
  • 3
  • 21
  • 54