PHP 8.3.4 Released!

Stomp::subscribe

stomp_subscribe

(PECL stomp >= 0.1.0)

Stomp::subscribe -- stomp_subscribeRegisters to listen to a given destination

説明

オブジェクト指向型 (method):

public Stomp::subscribe(string $destination, array $headers = ?): bool

手続き型:

stomp_subscribe(resource $link, string $destination, array $headers = ?): bool

Registers to listen to a given destination.

パラメータ

link

手続き型のみ: stomp_connect() が返す stomp リンク ID。

destination

Destination to subscribe to.

headers

追加のヘッダ (例: receipt) を含む連想配列。

戻り値

成功した場合に true を、失敗した場合に false を返します。

See stomp_ack().

注意

ヒント

Stomp は本来非同期です。同期通信を実装するには receipt ヘッダを追加します。これを追加すると、サーバーがメッセージを受領するかタイムアウトに達するまではメソッドが何も返さないようになります。

add a note

User Contributed Notes 1 note

up
-1
holycd
6 years ago
Using Topics from PHP over Stomp
$clientId = 'test:dev';
$topic = '/topic/perm.user';

try {
$stomp = new Stomp('tcp://localhost:61613','system','manager', array('client-id'=> $clientId ));
} catch(StompException $e) {
die('Connection failed: ' . $e->getMessage());
}

$isSubscribe = $stomp->subscribe($topic);

while($isSubscribe){
if ($stomp->hasFrame()) {
$frame = $stomp->readFrame();
if ($frame != NULL) {
print "Received: " . $frame->body . " - time now is " . date("Y-m-d H:i:s"). "\n";
// $stomp->ack($frame);
}
// sleep(1);
}
else {
print "No frames to read\n";
}
}
if($isSubscribe){
$stomp->unsubscribe($topic);
unset($stomp);
}

Can not receive the topic frame
To Top