PHP Velho Oeste 2024

Opérations de messagerie

Toutes les opérations de messagerie sont exécutées via des appels aux méthodes sur l'objet de connexion. Pour ajouter un message à la file d'attente, la méthode "send" est utilisée, tandis que pour obtenir un message depuis la file d'attente, la méthode "receive" est utilisée. D'autres méthodes offrent d'autres fonctionnalités comme la publication, la souscription ou encore le contrôle sur les transactions.

Exemple #1 Ajout d'un message à la file d'attente et réception de la réponse

<?php
$msg 
= new SAMMessage('Ceci est un message texte simple');
$msg->header->SAM_REPLY_TO 'queue://receive/test';
$correlid $conn->send('queue://send/test'$msg);

if (!
$correlid) {
  
// The Send failed!
  
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