Difference between revisions of "PHP Example"

From Open Rail Data Wiki
Jump to navigation Jump to search
(Created page with "<code> <?php // Network Rail Stomp Handler example by ian13 $server = "tcp://datafeeds.networkrail.co.uk:61618"; $user = "username"; $password = "password"; $channel = "TRA…")
 
m (mixed random new line in the middle)
Line 6: Line 6:
 
  $password = "password";
 
  $password = "password";
 
  $channel = "TRAIN_MVT_ALL_TOC";
 
  $channel = "TRAIN_MVT_ALL_TOC";
 
+
 
  $con = new Stomp($server, $user, $password);
 
  $con = new Stomp($server, $user, $password);
 
  if (!$con) {
 
  if (!$con) {

Revision as of 17:33, 26 July 2012

<?php
// Network Rail Stomp Handler example by ian13
$server = "tcp://datafeeds.networkrail.co.uk:61618";
$user = "username";
$password = "password";
$channel = "TRAIN_MVT_ALL_TOC";

$con = new Stomp($server, $user, $password);
if (!$con) {
   die('Connection failed: ' . stomp_connect_error());
}
$con->subscribe("/topic/" . $channel);
while($con){
   if ($con->hasFrame()){
       $msg = $con->readFrame();
       foreach (json_decode($msg->body) as $event) {
         // do stuff with $event here
       }
       $con->ack($msg);
   }
}
die('Connection lost: ' . time());
?>

Requires PECL STOMP package (just type "pecl install stomp" in the command line).