PHP for reading the subway GTFS-realtime feed

1,136 views
Skip to first unread message

Michael Frumin

unread,
Jan 25, 2013, 6:42:25 PM1/25/13
to MTA Developers
Has anyone gone through the process to set up PHP classes to parse/read the subway realtime feed protocol buffer file? I am interested in doing a little project on my own but I have never really done protobuf's before and if someone has compiled the objects in PHP then it would save me the major setup/overhead that could eat up a whole weekend afternoon.

Thanks!
Mike


Jym Dyer

unread,
Jan 25, 2013, 7:57:46 PM1/25/13
to mtadevelop...@googlegroups.com
Google maintains a list of language add-ons to parse protobufs:

http://code.google.com/p/protobuf/wiki/ThirdPartyAddOns

I haven't tried the PHP one, but it looks like it constructs class instances.
<_Jym_>

Jonathan Vingiano

unread,
Jan 25, 2013, 8:31:32 PM1/25/13
to mtadevelop...@googlegroups.com
I wrote a library for this http://github.com/jgv/sandhog

--
Jonathan Vingiano
Sent via mobile

Alex (Maxious) Sadleir

unread,
Jan 25, 2013, 7:48:56 PM1/25/13
to mtadevelop...@googlegroups.com

Yes.
First and foremost, you have to be using PHP 5.3+ because the library
relies heavily on namespaces.

My code for building and exporting protobuf GTFS-realtime objects is
here: https://github.com/maxious/ACTBus-ui/blob/master/include/common-transit.inc.php#L91
As you can see from the exporting functions
https://github.com/maxious/ACTBus-ui/blob/master/include/common-transit.inc.php#L323
once you make a PHP-protobuf object, you can export it as binary
protobuf (for use in OpenTripPlanner realtime changes) or just as a
PHP array.
And the library with a pre-compiled PHP version of the schema
("gtfs-realtime.php"):
https://github.com/maxious/ACTBus-ui/tree/master/lib/Protobuf-PHP

I seem to recall I had to remove some lines at the start of the proto
file to get it to compile (the ones about creative commons licencing
etc.) but those do not affect the operation.

I also have some simpler (no real database call) examples I used for
testing: https://github.com/maxious/ACTBus-ui/blob/master/lib/Protobuf-PHP/test-alert.php
https://github.com/maxious/ACTBus-ui/blob/master/lib/Protobuf-PHP/test-tripupdates.php

My code currently does not read protobuf objects from files (my
transit authority is moving back to SIRI already) but I have just put
up another test file demonstrating that functionality:
https://github.com/maxious/ACTBus-ui/blob/master/lib/Protobuf-PHP/test-import-alert.php
which opens https://github.com/maxious/ACTBus-ui/blob/master/lib/Protobuf-PHP/example-alert.proto
or any other valid GTFS-realtime file (alerts or route updates) and
converts it to a PHP array for ease of use.

Reply all
Reply to author
Forward
0 new messages