# Using Trip Planner example issue

**URL:** <https://opendataforum.transport.nsw.gov.au/t/using-trip-planner-example-issue/1650>\
**Category:** How to\
**Created:** [May 24, 2019, 2:21am UTC](https://opendataforum.transport.nsw.gov.au/t/using-trip-planner-example-issue/1650 "2019-05-24T02:21:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scout.Iris](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@Scout.Iris](https://opendataforum.transport.nsw.gov.au/u/Scout.Iris)\
**Post date:** [May 24, 2019, 2:21am UTC](https://opendataforum.transport.nsw.gov.au/t/using-trip-planner-example-issue/1650/1 "2019-05-24T02:21:57Z")

</div>

Hi eveyone, hoping that someone can help this first time GTFS user on the Trip planner example here:

> **[How to Build a Departure Board Using Open Data | TfNSW Open Data Hub and...](https://opendata.transport.nsw.gov.au/how-build-departure-board-using-open-data)**
>
> Transport for NSW's Open Data Portal

I have copied the full example PHP from the bottom of the page, and getting the following when running from [http://localhost:8888/gtfs/test.php](http://localhost:8888/gtfs/test.php).

**Warning** : file\_get\_contents([https://api.transport.nsw.gov.au/v1/tp/departure\_mon?outputFormat=rapidJSON&coordOutputFormat=EPSG%3A4326&mode=direct&type\_dm=stop&name\_dm=10101331&depArrMacro=dep&itdDate=20190524&itdTime=1211&TfNSWDM=true](https://api.transport.nsw.gov.au/v1/tp/departure_mon?outputFormat=rapidJSON&coordOutputFormat=EPSG%3A4326&mode=direct&type_dm=stop&name_dm=10101331&depArrMacro=dep&itdDate=20190524&itdTime=1211&TfNSWDM=true)): failed to open stream: Operation timed out in **/Applications/MAMP/htdocs/gtfs/test.php** on line **21**

**Warning** : Invalid argument supplied for foreach() in **/Applications/MAMP/htdocs/gtfs/test.php** on line **26**

Does anyone have a working example I could use, or PLEASE point me in the direction of what I am doing wrong. (PS I am using my API Key not the XXXX).

Many thanks

---

<div class="post-metadata">

**Author:** ![alejandro.felman](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@alejandro.felman](https://opendataforum.transport.nsw.gov.au/u/alejandro.felman)\
**Post date:** [May 24, 2019, 2:54am UTC](https://opendataforum.transport.nsw.gov.au/t/using-trip-planner-example-issue/1650/2 "2019-05-24T02:54:07Z")

</div>

Hi @Scout.Iris, welcome to our forum!

Hopefully a developer in our community will help you out with your issue. Since we can’t access your local files, it might be a good idea to post a full sample of your code so others can see it, after removing your API key of course!

Thanks!

---

<div class="post-metadata">

**Author:** ![Scout.Iris](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@Scout.Iris](https://opendataforum.transport.nsw.gov.au/u/Scout.Iris)\
**Post date:** [May 24, 2019, 4:14am UTC](https://opendataforum.transport.nsw.gov.au/t/using-trip-planner-example-issue/1650/4 "2019-05-24T04:14:28Z")

</div>

Thankyou so much for your help and assistance. The code below is straight from the example project, appreciate any help you can give me as Id love to be tinkering with this over the weekend.

```
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
date_default_timezone_set("Australia/Sydney");
$apiEndpoint = 'https://api.transport.nsw.gov.au/v1/tp/';
$apiCall = 'departure_mon'; // Set the location and time parameters
$when = time(); // Now
$stop = '10101331'; // Domestic Airport Station // Build the request parameters
$params = array( 'outputFormat' => 'rapidJSON', 'coordOutputFormat' => 'EPSG:4326', 'mode' => 'direct', 'type_dm' => 'stop', 'name_dm' => $stop, 'depArrMacro' => 'dep', 'itdDate' => date('Ymd', $when), 'itdTime' => date('Hi', $when), 'TfNSWDM' => 'true' );
$url = $apiEndpoint . $apiCall . '?' . http_build_query($params);

// Create a stream
$opts = [
    "http" => [
        "method" => "GET",
        "header" => "Authorization: apikey XXXXXX API KEY XXXXXX\r\n"
    ]
];

// Perform the request and build the JSON response data
$context = stream_context_create($opts);
$response = file_get_contents($url, false, $context);
$json = json_decode($response, true);
$stopEvents = $json['stopEvents']; 

// Loop over returned stop events
foreach ($stopEvents as $stopEvent) {
    // Extract the route information
    $transportation = $stopEvent['transportation'];
    $routeNumber = $transportation['number'];
    $destination = $transportation['destination']['name']; // In the case of a train, the location includes platform information
    $location = $stopEvent['location']; // Determine how many minutes until departure
    $time = strtotime($stopEvent['departureTimePlanned']);
    $countdown = $time - time();
    $minutes = round($countdown / 60); // Output the stop event with a countdown timer
    echo $minutes . "m from " . $location['name'] . "\n<br />";
    echo $routeNumber . " to " . $destination . "\n\n<br /><br />";
}

echo "end";
?>

```

---

<div class="post-metadata">

**Author:** ![Scout.Iris](https://avatars.discourse-cdn.com/v4/letter/s/46a35a/32.png) [@Scout.Iris](https://opendataforum.transport.nsw.gov.au/u/Scout.Iris)\
**Post date:** [May 25, 2019, 1:28am UTC](https://opendataforum.transport.nsw.gov.au/t/using-trip-planner-example-issue/1650/5 "2019-05-25T01:28:30Z")

</div>

No reason to respond, I have managed to work out the problem. My office firewall was preventing the call from executing and returning a feed.  
Running from outside the firewall was successful.

Cheers
