PHPackages                             dacoto/gtfs-rt-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dacoto/gtfs-rt-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dacoto/gtfs-rt-php
==================

GTFS-Realtime library for PHP 8.4+ based on Google Protocol Buffers v5

v1.0.0(1mo ago)19↑2900%MITPHPPHP &gt;=8.4CI passing

Since Mar 28Pushed 1mo agoCompare

[ Source](https://github.com/dacoto/gtfs-rt-php)[ Packagist](https://packagist.org/packages/dacoto/gtfs-rt-php)[ Fund](https://www.buymeacoffee.com/dacoto)[ Fund](https://www.paypal.com/donate/?hosted_button_id=SGZ2VZ52ZD378)[ RSS](/packages/dacoto-gtfs-rt-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

[![GTFS-RT PHP](./gtfs-rt-php.png)](./gtfs-rt-php.png)

GTFS RT PHP
===========

[](#gtfs-rt-php)

GTFS-Realtime library for PHP 8.4+ based on Google's [Protocol Buffers](https://github.com/protocolbuffers/protobuf) v5.

A modern PHP implementation of the [GTFS Realtime](https://gtfs.org/documentation/realtime/reference/) specification. The proto definition was downloaded from [gtfs.org](https://gtfs.org/documentation/realtime/gtfs-realtime.proto) and converted to proto3 syntax for compatibility with the latest `google/protobuf` PHP library.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.4
- [google/protobuf](https://packagist.org/packages/google/protobuf) ^5.34

Installation
------------

[](#installation)

```
composer require dacoto/gtfs-rt-php
```

Usage
-----

[](#usage)

### Creating a Feed Message

[](#creating-a-feed-message)

```
use Google\Transit\Realtime\FeedMessage;
use Google\Transit\Realtime\FeedHeader;
use Google\Transit\Realtime\FeedHeader\Incrementality;
use Google\Transit\Realtime\FeedEntity;
use Google\Transit\Realtime\TripUpdate;
use Google\Transit\Realtime\TripUpdate\StopTimeUpdate;
use Google\Transit\Realtime\TripUpdate\StopTimeEvent;
use Google\Transit\Realtime\TripDescriptor;

$feedMessage = new FeedMessage();

$header = new FeedHeader();
$header->setGtfsRealtimeVersion('2.0');
$header->setIncrementality(Incrementality::FULL_DATASET);
$header->setTimestamp(time());
$feedMessage->setHeader($header);

$entity = new FeedEntity();
$entity->setId('entity-1');

$tripDescriptor = new TripDescriptor();
$tripDescriptor->setTripId('trip-123');
$tripDescriptor->setRouteId('route-42');

$arrivalEvent = new StopTimeEvent();
$arrivalEvent->setDelay(120); // 2 minutes late

$stopTimeUpdate = new StopTimeUpdate();
$stopTimeUpdate->setStopSequence(1);
$stopTimeUpdate->setStopId('stop-A');
$stopTimeUpdate->setArrival($arrivalEvent);

$tripUpdate = new TripUpdate();
$tripUpdate->setTrip($tripDescriptor);
$tripUpdate->setStopTimeUpdate([$stopTimeUpdate]);

$entity->setTripUpdate($tripUpdate);
$feedMessage->setEntity([$entity]);

// Serialize to binary protobuf
$binaryData = $feedMessage->serializeToString();
```

### Parsing a Feed Message

[](#parsing-a-feed-message)

```
use Google\Transit\Realtime\FeedMessage;

$binaryData = file_get_contents('https://your-agency.com/gtfs-rt/tripupdates.pb');

$feedMessage = new FeedMessage();
$feedMessage->mergeFromString($binaryData);

echo "GTFS-RT version: " . $feedMessage->getHeader()->getGtfsRealtimeVersion() . PHP_EOL;

foreach ($feedMessage->getEntity() as $entity) {
    if ($entity->hasTripUpdate()) {
        $tripUpdate = $entity->getTripUpdate();
        echo "Trip ID: " . $tripUpdate->getTrip()->getTripId() . PHP_EOL;

        foreach ($tripUpdate->getStopTimeUpdate() as $stu) {
            if ($stu->hasArrival()) {
                echo "  Stop " . $stu->getStopId() . " delay: " . $stu->getArrival()->getDelay() . "s" . PHP_EOL;
            }
        }
    }
}
```

See full examples in the [examples/](examples/) directory.

Proto3 Conversion Notes
-----------------------

[](#proto3-conversion-notes)

The official GTFS Realtime proto uses `proto2` syntax. This library converts it to `proto3` to be compatible with the latest `google/protobuf` PHP library. The key changes are:

1. Changed `syntax = "proto2"` to `syntax = "proto3"`
2. Removed all `optional` and `required` field labels (all fields are optional in proto3)
3. Removed all `extensions` ranges (not supported in proto3)
4. Removed all explicit `[default = ...]` values
5. Added `UNKNOWN_CAUSE = 0`, `NO_SERVICE = 0`, and `UNKNOWN_SEVERITY = 0` as first enum values (proto3 requires first value to be 0)
6. Added PHP namespace options: `php_namespace` and `php_metadata_namespace`

Running Tests
-------------

[](#running-tests)

```
composer install
vendor/bin/phpunit
```

Regenerating PHP Classes
------------------------

[](#regenerating-php-classes)

The PHP classes in `src/` are generated automatically from `gtfs-realtime.proto` using `protoc`.

### Automatic (GitHub Actions)

[](#automatic-github-actions)

Every time `composer.json` or `gtfs-realtime.proto` is changed on `main`, the [Regenerate PHP Classes](.github/workflows/generate.yml) workflow runs automatically, downloads the correct `protoc` binary, regenerates all PHP classes, and commits the result.

You can also trigger it manually from the **Actions** tab, optionally overriding the `protoc` version.

### Manual (local)

[](#manual-local)

Run the generation script — it resolves the `protoc` version from `composer.json` (or `composer.lock`) automatically:

```
bash bin/generate.sh
```

Or override the protoc version explicitly:

```
bash bin/generate.sh --protoc-version 34.1
```

The script:

1. Reads the `google/protobuf` version from `composer.lock` (or `composer.json`)
2. Derives the matching `protoc` release (e.g. PHP `v5.34.1` → `protoc v34.1`)
3. Downloads the `protoc` binary from [github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf/releases)
4. Regenerates all PHP classes in `src/` from `gtfs-realtime.proto`

License
-------

[](#license)

MIT — See [LICENSE](LICENSE)

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance90

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

46d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe58dc29067fa49a3c68086edeba0f324ce342118432e34a5556954c7d3a8fbf?d=identicon)[dacoto](/maintainers/dacoto)

---

Top Contributors

[![dacoto](https://avatars.githubusercontent.com/u/16915053?v=4)](https://github.com/dacoto "dacoto (1 commits)")

---

Tags

gtfsgtfs-realtimegtfs-rtphpprotobuftransitprotobuftransitgtfs-realtimegtfs

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dacoto-gtfs-rt-php/health.svg)

```
[![Health](https://phpackages.com/badges/dacoto-gtfs-rt-php/health.svg)](https://phpackages.com/packages/dacoto-gtfs-rt-php)
```

###  Alternatives

[alibaba/nacos

阿里巴巴nacos配置中心php客户端

19340.8k1](/packages/alibaba-nacos)[hasanmertermis/milvus-php-client

Milvus 2 Grpc Php Client

142.1k](/packages/hasanmertermis-milvus-php-client)[davidrjenni/scip-php

SCIP Code Intelligence Protocol (SCIP) indexer for PHP

161.2k](/packages/davidrjenni-scip-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
