You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Schulze <sc...@gmx.net> on 2007/06/06 11:58:29 UTC

ActiveMQ + PHP + Stomp = ActiveStack ??

I tried to use ActiveMQ 4.1.1 with stomp connector from PHP (after porting
Stomp.php for use with PHP5). Surprisingly it behaves like a stack:

===
producer.php:
----
<?php
require_once 'Stomp5.php';

header('Content-type: text/plain');

function send($msg) {
    global $c;
    $c->subscribe('/queue/FOO');
    $c->send('/queue/FOO', $msg, array('expires' => 1));
    print 'sent: '.$msg.PHP_EOL;
}

$c = new StompConnection('localhost');
$result = $c->connect('producer', 'test');
$c->subscribe('/queue/FOO');

send('Hello World!');
send('Hello Mars!');

$c->disconnect();
?>
----
sent: Hello World!
sent: Hello Mars!
===

===
consumer.php
---
<?php
require_once 'Stomp5.php';

header('Content-type: text/plain');

function consume() {
    $c = new StompConnection('localhost', 5);
    $result = $c->connect('bobo', 'test');
    $c->subscribe('/queue/FOO');
    $result = $c->receive();
    print 'read: '.$result->body . PHP_EOL;
    $c->acknowledge($result->headers['message-id']);
    $c->disconnect();
    return true;
}

consume();
consume();

?>
---
read: Hello Mars!
read: Hello World!
===

Am I wrong?
-- 
View this message in context: http://www.nabble.com/ActiveMQ-%2B-PHP-%2B-Stomp-%3D-ActiveStack----tf3876949s2354.html#a10985635
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: ActiveMQ + PHP + Stomp = ActiveStack ??

Posted by Tom Samplonius <to...@samplonius.org>.
----- "Hiram Chirino" <hi...@hiramchirino.com> wrote:
> That's awesome..  Has anybody put stuff up on http://pecl.php.net
> before??  I think that would be the best place to host the PHP Stomp
> impl.  What do you guys think?
> 
> Regards,
> Hiram


  If you do that, make sure to include a note to use a 4.2-SNAPSHOT version, and not 4.1.1.

  4.1.1 Stomp support is buggy.  Stomp consumers that crash, will lose all un-acked messages.  Basically, ActiveMQ 4.1.1 only recovers un-acked Stomp messages, if the socket is cleanly closed with a DISCONNECT.  So if there is a network problem, or something, and the client loses its connect, the un-acked message(s) from the previous session are gone.

Tom 

Re: ActiveMQ + PHP + Stomp = ActiveStack ??

Posted by Hiram Chirino <hi...@hiramchirino.com>.
Coolio..

looks like someone needs to review the code and make it compliant with
their coding standards first:

http://pear.php.net/manual/en/standards.php

Regards,
Hiram

On 6/11/07, PieterN <se...@internethoofdkantoor.nl> wrote:
>
>
>
> Hiram Chirino wrote:
> >
> > That's awesome..  Has anybody put stuff up on http://pecl.php.net
> > before??  I think that would be the best place to host the PHP Stomp
> > impl.  What do you guys think?
> >
> IMHO PEAR (http://pear.php.net/) is a better place. PECL is for external
> libraries (i.e., extensions which have to be compiled and are loaded by PHP
> as a dynamic library).
>
> Regards,
>
> Pieter
> --
> View this message in context: http://www.nabble.com/ActiveMQ-%2B-PHP-%2B-Stomp-%3D-ActiveStack----tf3876949s2354.html#a11060579
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>


-- 
Regards,
Hiram

Blog: http://hiramchirino.com

Re: ActiveMQ + PHP + Stomp = ActiveStack ??

Posted by PieterN <se...@internethoofdkantoor.nl>.


Hiram Chirino wrote:
> 
> That's awesome..  Has anybody put stuff up on http://pecl.php.net
> before??  I think that would be the best place to host the PHP Stomp
> impl.  What do you guys think?
> 
IMHO PEAR (http://pear.php.net/) is a better place. PECL is for external
libraries (i.e., extensions which have to be compiled and are loaded by PHP
as a dynamic library).

Regards,

Pieter
-- 
View this message in context: http://www.nabble.com/ActiveMQ-%2B-PHP-%2B-Stomp-%3D-ActiveStack----tf3876949s2354.html#a11060579
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: ActiveMQ + PHP + Stomp = ActiveStack ??

Posted by Hiram Chirino <hi...@hiramchirino.com>.
That's awesome..  Has anybody put stuff up on http://pecl.php.net
before??  I think that would be the best place to host the PHP Stomp
impl.  What do you guys think?

Regards,
Hiram

On 6/6/07, Schulze <sc...@gmx.net> wrote:
>
> Yeaahhh, it works. The point was not to subscribe the procucer. Now I get the
> messages even in the expected order. Thanks a lot for your help, Atis-3!!
>
>
> The PHP5 port may be found here:
>
> http://www.nabble.com/file/p10988110/Stomp5.php Stomp5.php
> --
> View this message in context: http://www.nabble.com/ActiveMQ-%2B-PHP-%2B-Stomp-%3D-ActiveStack----tf3876949s2354.html#a10988110
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>


-- 
Regards,
Hiram

Blog: http://hiramchirino.com

Re: ActiveMQ + PHP + Stomp = ActiveStack ??

Posted by Schulze <sc...@gmx.net>.
Yeaahhh, it works. The point was not to subscribe the procucer. Now I get the
messages even in the expected order. Thanks a lot for your help, Atis-3!!


The PHP5 port may be found here:

http://www.nabble.com/file/p10988110/Stomp5.php Stomp5.php 
-- 
View this message in context: http://www.nabble.com/ActiveMQ-%2B-PHP-%2B-Stomp-%3D-ActiveStack----tf3876949s2354.html#a10988110
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: ActiveMQ + PHP + Stomp = ActiveStack ??

Posted by Atis <at...@BEST.eu.org>.
> Stomp.php uses deprecated socket functions. I have to follow a policy
> here... Now I use stream_socket_client() and fread(), fwrite() etc.

Could you be so kind and share it?

> > consumer.php: $c = new StompConnection('localhost', 5);
> > Why port 5?
> >
>
> 5 is the timeout in that case, port is 61613.

Seems you have another version of Stomp.php, the one i took had port
as second parameter

> > producer.php:  $c->subscribe('/queue/FOO');
> > Why subscribe in producer? With that i couldn't receive anything at
> > all in consumer.php.
> >
>
> How does the consumer know witch queue to read if not subscribed? For me I
> can *not* receive if I'm *not* subscribed.
>
> The point is, I receive messages with my scripts, but not in the expected
> order.

No, i mean why to subscribe in producer.php. You are sending messages,
and you specify to what queue.

Regards,
Atis

Re: ActiveMQ + PHP + Stomp = ActiveStack ??

Posted by Schulze <sc...@gmx.net>.

Atis-3 wrote:
> 
> I wonder, why you would need to convert Stomp.php to PHP5. 
> 

Stomp.php uses deprecated socket functions. I have to follow a policy
here... Now I use stream_socket_client() and fread(), fwrite() etc.


Atis-3 wrote:
> 
> consumer.php: $c = new StompConnection('localhost', 5);
> Why port 5?
> 

5 is the timeout in that case, port is 61613.


Atis-3 wrote:
> 
> producer.php:  $c->subscribe('/queue/FOO');
> Why subscribe in producer? With that i couldn't receive anything at
> all in consumer.php.
> 

How does the consumer know witch queue to read if not subscribed? For me I
can *not* receive if I'm *not* subscribed.

The point is, I receive messages with my scripts, but not in the expected
order.

-- 
View this message in context: http://www.nabble.com/ActiveMQ-%2B-PHP-%2B-Stomp-%3D-ActiveStack----tf3876949s2354.html#a10987354
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: ActiveMQ + PHP + Stomp = ActiveStack ??

Posted by Atis <at...@BEST.eu.org>.
On 6/6/07, Schulze <sc...@gmx.net> wrote:
>
> I tried to use ActiveMQ 4.1.1 with stomp connector from PHP (after porting
> Stomp.php for use with PHP5). Surprisingly it behaves like a stack:

Hi,

I wonder, why you would need to convert Stomp.php to PHP5. I took mine
from https://svn.codehaus.org/stomp/trunk/php/ and it works for me.

As for your sample:

consumer.php: $c = new StompConnection('localhost', 5);
Why port 5?

producer.php:  $c->subscribe('/queue/FOO');
Why subscribe in producer? With that i couldn't receive anything at
all in consumer.php.

With those modifications, it worked fine with snapshot
apache-activemq-4.2-20070516.230525-60

Regards,
Atis