Simple Asynchronous Messaging Using PHP

Simple Asynchronous Messaging Using PHP

IBM has created an extension to PHP called SAM that provides access to the functionality of messaging and queuing systems from PHP scripts. Reliable messaging and queuing processes are essential for connecting, communicating, and transporting information between applications and various business systems. Robust messaging and queuing systems remove the details of any network or communication technology from the sender and receiver applications and allows the sender and receiver to work asynchronously. They work across multiple network and operating system technologies, and scale to very large numbers of endpoints. These systems also work in conjunction with publish and subscribe processes that allow messages to be published and received according to specific criteria (or topics).However, while the concepts of messaging are simple to understand, creating the APIs to these systems is not. A recent project called Simple Asynchronous Messaging (SAM) simplifies the process of accessing messaging and queuing systems by converting the APIs into scripting languages including PHP. SAM is an open source implementation available from PECL—a repository for PHP extensions, providing a directory of extensions and hosting facilities for downloading and development of PHP extensions. SAM uses an API that is designed to be messaging system neutral.

The SAM extension has an interface designed to make it extremely simple to do commonly required tasks such as deliver simple text messages to queues while still allowing you to do more complex messaging operations. In most cases it allows you to simply ignore the complexities of having to set up numerous options. The SAM extension is a small, stateless extension written in C that can be built for either PHP 5 or PHP 4 and is available for download.

The SAM extension currently allows applications to access queues or use publish and subscribe with a broad range of the IBM Messaging and Queuing family of products including WebSphere MQSeries, WebSphere Application Server and WebSphere Event Broker.

The following is an example of how to send a message to a queue using PHP

// Create a connection  $conn = new SAMConnection();  

if ($conn->connect(SAM_WMQ, 

array (SAM_BROKER => ‘MyBroker’))) {

//Create a message   
$msg = new SAMMessage(‘Simple text message’);    
//Send it   
if (!$conn->send(‘queue://send/test’, $msg)) {     
// Oh dear the send failed!   
}
}
else 
{  
// Oh dear we didn’t successfully connect! 
}

 

 

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.