PHP Example: Difference between revisions

From Open Rail Data Wiki
m mixed random new line in the middle
m Redirected to new PHP examples page
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<code>
#REDIRECT [[PHP_Examples]]
<?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());
?>
</code>
 
Requires PECL STOMP package (just type "pecl install stomp" in the command line).

Latest revision as of 17:52, 9 July 2013

Redirect to: