PHP Velho Oeste 2024

メッセージング操作

すべてのメッセージング操作は、接続オブジェクトのメソッドをコールすることで行います。 キューにメッセージを追加するには "send" メソッドを使用し、 キューからメッセージを取得するには "receive" メソッドを使用します。 その他のメソッドには、配信や購読機能、 そしてトランザクションの境界の制御などがあります。

例1 キューへのメッセージの追加および応答の取得

<?php
$msg 
= new SAMMessage('This is a simple text message');
$msg->header->SAM_REPLY_TO 'queue://receive/test';
$correlid $conn->send('queue://send/test'$msg);

if (!
$correlid) {
  
// 送信に失敗しました!
  
echo "Send failed ($conn->errno$conn->error";
} else {
  
$resp $conn->receive('queue://receive/test', array(SAM_CORRELID => $correlid));
}
?>

add a note add a note

User Contributed Notes 1 note

up
2
a dot hoyau at silexlabs dot org
12 years ago
Hello

I think that most people people coming here are looking to do this on client side, in client/server web applications

Sam is not made for this, but to connect servers together - systems in fact. See http://project-sam.awardspace.com/overview.htm

Since PHP is stateless it is really hard to do collaborative applications with a PHP back-end and very few solutions exist. So, for those looking for this, I put here a link to a messaging server in PHP - free open source and community driven: http://php-polling.sourceforge.net/

Hoping this will make you save time!
To Top