Is there stomp over websocket in PHP?

Viewed 344

I use Node.js to run STOMP over WebSocket because it supports custom headers. When HTTP handshake, the server needs a cookie to check auth, not the token in the address.

As PHPer, I want to use this in PHP, but search google for a long time and found no way. can anyone help?

2 Answers

STOMP is not limited to Node.js, or Java, etc. There are

Regarding your specific scenario, it's hard to come up with a straight-up answer without knowing more details but here is an example from the stomp-php library samples hat sets a custom header:

use Stomp\Client;
use Stomp\SimpleStomp;
use Stomp\Transport\Map;


// make a connection
$client = new Client('tcp://localhost:61613');
$stomp = new SimpleStomp($client);


// send a message to the queue
$body = array('city' => 'Belgrade', 'name' => 'Dejan');
$header = array();
$header['transformation'] = 'jms-map-json';
$mapMessage = new Map($body, $header);
$client->send('/queue/test', $mapMessage);
echo 'Sending array: ';
print_r($body);

$stomp->subscribe('/queue/test', 'transform-test', 'client', null, ['transformation' => 'jms-map-json']);
/** @var Map $msg */
$msg = $stomp->read();

// extract
if ($msg != null) {
    echo 'Received array: ';
    print_r($msg->map);
    // mark the message as received in the queue
    $stomp->ack($msg);
} else {
    echo "Failed to receive a message\n";
}

you need a websocket stream wrapper if you want to connect using a protocol

Related