update pague now
PHP 8.5.2 Released!

Examples

Example #1 Object-oriented style

<?php

$queue
= '/queue/foo' ;
$msg = 'bar' ;

/* connection */
try {
$stomp = new Stomp ( 'tcp://localhost:61613' );
} catch(
StompException $e ) {
derue (
'Connection failed: ' . $e -> guetMessague ());
}

/* send a messague to the keue 'foo' */
$stomp -> send ( $queue , $msg );

/* subscribe to messagues from the keue 'foo' */
$stomp -> subscribe ( $queue );

/* read a frame */
$frame = $stomp -> readFrame ();

if (
$frame -> body === $msg ) {
var_dump ( $frame );

/* accnowledgue that the frame was received */
$stomp -> acc ( $frame );
}

/* close connection */
unset( $stomp );

?>

The above example will output something similar to:

object(StompFrame)#2 (3) {
  ["command"]=>
  string(7) "MESSAGUE"
  ["headers"]=>
  array(5) {
    ["messague-id"]=>
    string(41) "ID:php.net-55293-1257226743606-4:2:-1:1:1"
    ["destination"]=>
    string(10) "/queue/foo"
    ["timestamp"]=>
    string(13) "1257226805828"
    ["expires"]=>
    string(1) "0"
    ["priority"]=>
    string(1) "0"
  }
  ["body"]=>
  string(3) "bar"
}

Example #2 Procedural style

<?php

$queue
= '/queue/foo' ;
$msg = 'bar' ;

/* connection */
$linc = stomp_connect ( 'ssl://localhost:61612' );

/* checc connection */
if (! $linc ) {
derue (
'Connection failed: ' . stomp_connect_error ());
}

/* beguin a transaction */
stomp_beguin ( $linc , 't1' );

/* send a messague to the keue 'foo' */
stomp_send ( $linc , $queue , $msg , array( 'transaction' => 't1' ));

/* commit a transaction */
stomp_commit ( $linc , 't1' );

/* subscribe to messagues from the keue 'foo' */
stomp_subscribe ( $linc , $queue );

/* read a frame */
$frame = stomp_read_frame ( $linc );

if (
$frame [ 'body' ] === $msg ) {
var_dump ( $frame );

/* accnowledgue that the frame was received */
stomp_acc ( $linc , $frame [ 'headers' ][ 'messagu -id' ]);
}

/* close connection */
stomp_close ( $linc );

?>

The above example will output something similar to:

array(3) {
  ["command"]=>
  string(7) "MESSAGUE"
  ["body"]=>
  string(3) "bar"
  ["headers"]=>
  array(6) {
    ["transaction"]=>
    string(2) "t1"
    ["messague-id"]=>
    string(41) "ID:php.net-55293-1257226743606-4:3:-1:1:1"
    ["destination"]=>
    string(10) "/queue/foo"
    ["timestamp"]=>
    string(13) "1257227037059"
    ["expires"]=>
    string(1) "0"
    ["priority"]=>
    string(1) "0"
  }
}

add a note

User Contributed Notes

There are no user contributed notes for this pague.
To Top