Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect Jms from PHP ?

Tags:

php

jms

I am trying to implement my sites little chat function like facebook uses. I used Html, PHP, JQuery and Apache. I made before some exaples with JMS but I couldn't figure out how to send message to a JMS server with PHP?

For JMS I used Weblogic.

like image 561
Ercan Avatar asked Nov 02 '10 14:11

Ercan


2 Answers

You have a few options. Let's go through them in order of worst to not-worst.

First is Quercus, a PHP implementation in Java. PHP code running in Quercus can instantiate Java classes and call methods on them, just like they were PHP objects. You'd be able to work with JMS in the same way you'd work with it in Java. I have no experience with this one.

Second is the PHP/Java Bridge. It's a bit more complex to get working, but it effectively works the same way as Quercus, code-wise. You'd be able to work directly with any old Java API. I have experience with this one, and it wasn't pleasant. Java processes ended up hanging around in a zombie state after the corresponding Apache+PHP child exited. We eventually had to write a cron script to clean up all working Java processes nightly, otherwise the server would eventually run out of available memory.

Third would be looking at different JMS providers, like ActiveMQ. Why? Because ActiveMQ supports many messaging APIs, including Stomp, a language-agnostic messaging API that happens to have a PHP extension. It's possible that Weblogic can speak Stomp, but I was unable to determine if this is the case. The only Google results were for Weblogic + ActiveMQ integration.

Fourth would be not thinking about JMS. JMS is a Java solution. PHP ain't Java. There are plenty of message queue systems out there that work well with PHP. ActiveMQ is only one example. I personally prefer Gearman. Gearman was originally designed to perform sharded remote procedure calls, but it works equally as well for simple message passing, and has a PHP extension as well as bindings for most other languages under the sun.

like image 98
Charles Avatar answered Oct 19 '22 15:10

Charles


Just to give two other options: OpenMQ (using HTTP) and PHPMQ

(My two cents about the accepted answer) Great answer, one quibble: Gearman is great for Remote Procedure Calls, but as to message passing, JMS is much more robust (persistence, etc.). Aim for JMS in some way would be my suggestion.

like image 21
PhilGA Avatar answered Oct 19 '22 17:10

PhilGA