PHP Examples

There are two ways to access the Network Rail data feeds from PHP: the PECL Stomp package or the Stomp library.

PECL Stomp Package
The PECL Stomp Package can be installed through the PECL command line tool; this is part of the PHP PEAR extensions package. Instructions for installing PEAR and PECL on different systems can be found by searching the web. Once PECL is installed, type  at the command line.

Documentation for the PECL Stomp package can be found on the PHP:Stomp Manual page.

Basic Example
This example connects to the Network Rail data feed via STOMP, subscribes to the  topic, and sets up a loop listening for new frames.

Durable Subscriptions
The example above will only receive messages while it is connected to the STOMP server. By specifying a  header in the connection, and an   header in the subscription, messages that were sent while the client was offline will be received upon connection.

Stomp library
An alternative Stomp client is available from Fuse Source. It has some minor issues, such as injecting spaces in the username/password, and sleeping on message retrieval.

A fixed version can be obtained from here or here.