透過 Stomp 從 PHP 使用主題
$clientId = 'test:dev';
$topic = '/topic/perm.user';
try {
$stomp = new Stomp('tcp://127.0.0.1:61613','system','manager', array('client-id'=> $clientId ));
} catch(StompException $e) {
die('連線失敗:' . $e->getMessage());
}
$isSubscribe = $stomp->subscribe($topic);
while($isSubscribe){
if ($stomp->hasFrame()) {
$frame = $stomp->readFrame();
if ($frame != NULL) {
print "已收到:" . $frame->body . " - 現在時間是 " . date("Y-m-d H:i:s"). "\n";
// $stomp->ack($frame);
}
// sleep(1);
}
} else {
print "沒有要讀取的框架\n";
}
}
}
if($isSubscribe){
$stomp->unsubscribe($topic);
}
unset($stomp);