The following code only works with php sapobroker extension 0.4 using PHP 5.
<?php
// instantiate the broker handle
$broker = broker_init("127.0.0.1", SB_PORT, SB_TCP, SB_PROTOBUF);
// adding another server
broker_add_server($broker, "127.0.0.1", SB_PORT, SB_TCP, SB_PROTOBUF);
/* ... do some work */
/* allways close your broker connection */
broker_destroy($broker);
<?php
// ... connect to broker ...
$msg = "Hello World!";
broker_publish($broker, "/test/foo", $msg);
<?php
// ... connect to broker ...
$msg = "Hello World!";
broker_enqueue($broker, "/test/foo", $msg);
<?php
// ... connect to broker ...
$ret = broker_subscribe_queue($broker, "/test/foo", 0);
$timeout = 1000;
while (true) {
/*
This call will block until a timeout is reached,
an error occurred or a message is received.
*/
$msg = broker_receive($broker, $timeout);
if($msg !== false){
$msg_data = broker_msg_decode($msg);
echo "Got message: " . print_r($msg_data, true) . "\n";
/* ... do some work ... */
broker_msg_ack($msg); // don't forget to acknowledge the message reception
}
if( /*... exit condition ...*/ ){
break;
}
}
<?php
// ... connect to broker ...
$ret = broker_subscribe_topic($broker, "/test/foo");
$timeout = 1000;
while (true) {
/*
This call will block until a timeout is reached,
an error occurred or a message is received.
*/
$msg = broker_receive($broker, $timeout);
if($msg !== false){
$msg_data = broker_msg_decode($msg);
echo "Got message: " . print_r($msg_data, true) . "\n";
}
if( /*... exit condition ...*/){
break;
}
}
<?php
// ... connect to broker ...
$ret = broker_subscribe_queue($broker, "/test/foo", 0);
$timeout = 1000;
while (true) {
/*
This call will block until a timeout is reached,
an error occurred or a message is received.
*/
$msg = broker_receive($broker, $timeout, true);
if($msg !== false){
echo "Got message: " . print_r($msg, true) . "\n";
}
if( /*... exit condition ...*/){
break;
}
}