PHPackages                             keinos/mastodon-streaming-api-parser - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. keinos/mastodon-streaming-api-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

keinos/mastodon-streaming-api-parser
====================================

Parses the Mastodon Streaming API server-sent events to JSON.

1.0.1(5y ago)22841MITPHPPHP ^8.0 || ^7.1CI failing

Since Jul 12Pushed 5y agoCompare

[ Source](https://github.com/KEINOS/Mastodon_StreamingAPI_Parser)[ Packagist](https://packagist.org/packages/keinos/mastodon-streaming-api-parser)[ Docs](https://github.com/KEINOS/Mastodon_StreamingAPI_Parser)[ RSS](/packages/keinos-mastodon-streaming-api-parser/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (10)Versions (8)Used By (1)

[![](https://camo.githubusercontent.com/95f8e888dee5ab2bed66e0bb80b7704fccf3b1907ebe75b958fab182aac27d46/68747470733a2f2f7472617669732d63692e6f72672f4b45494e4f532f4d6173746f646f6e5f53747265616d696e674150495f5061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/KEINOS/Mastodon_StreamingAPI_Parser "View Build Status on Travis")[![](https://camo.githubusercontent.com/560fa17c7cb5bc1aef60b1ea7c07d415e09e29ce1992737753e2dd4e129e0293/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6769746875622f4b45494e4f532f4d6173746f646f6e5f53747265616d696e674150495f506172736572)](https://coveralls.io/github/KEINOS/Mastodon_StreamingAPI_Parser?branch=master "Code Coverage on COVERALLS")[![](https://camo.githubusercontent.com/6b2f33c3ea133bf368a225bf42ab4cef386d11fd8bd2c7491ee3851efdee4856/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f4b45494e4f532f4d6173746f646f6e5f53747265616d696e674150495f5061727365722f6d6173746572)](https://scrutinizer-ci.com/g/KEINOS/Mastodon_StreamingAPI_Parser/?branch=master "Code quality in Scrutinizer")[![](https://camo.githubusercontent.com/d8e6cafb4e3f3a16a6f589a338db40171be821ef45fc0371e885d5a4abfb3f7f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6b65696e6f732f6d6173746f646f6e2d73747265616d696e672d6170692d706172736572)](https://github.com/KEINOS/Mastodon_StreamingAPI_Parser/blob/master/.travis.yml "Version Support")

Server-Sent Events parser of Mastodon Streaming API in PHP
==========================================================

[](#server-sent-events-parser-of-mastodon-streaming-api-in-php)

This class simply parses the received lines from [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) of the [Mastodon Streaming API](https://docs.joinmastodon.org/methods/timelines/streaming/) to JSON object string.

The below lines (server-sent event messages) will be parsed in JSON as below.

```
5b1
event: update
data: {"id":"10000 ... visible\">0FS8QET2TTparse($line);
    if (false === $json) {
        continue;
    }
    echo $json . PHP_EOL;
}
```

↓

```
{"event":"update","payload":{"id":"10000 ... visible\">0FS8QET2TTparse($line);
    ```
- Returned JSON string structure

    ```
    {
        "event":"[Event name]",
        "payload":"[Data of the event]"
    }
    ```
- Interface: [ParserInterface.php](https://github.com/KEINOS/Mastodon_StreamingAPI_Parser/blob/master/src/interfaces/ParserInterface.php)

### Sample

[](#sample)

```
// Instantiate the parser
$parser = new \KEINOS\MSTDN_TOOLS\Parser\Parser();
// Open socket
$fp = fsockopen($hostname, $port, $errno, $errstr, $timeout);
// Send GET request
fwrite($fp, $req);
// Looper
while (! feof($fp)) {
    // Read the stream
    $read = fgets($fp);
    // Buffer each line until it returns the data
    $json = $parser->parse($read);
    if (false === $json) {
        continue;
    }
    // Do something with the data
    echo $json . PHP_EOL;
}
// Close connection
fclose($fp);
```

- Complete sample see: [./samples/Main.php](https://github.com/KEINOS/Mastodon_StreamingAPI_Parser/blob/master/samples/Main.php)

Specifications/Info
-------------------

[](#specificationsinfo)

- PHP: ^7.1 || ^8.0
- Available [event types](https://docs.joinmastodon.org/methods/timelines/streaming/#event-types-a-idevent-typesa) to detect: `update` and `delete`
- Source Code: [Mastodon\_StreamingAPI\_Parser](https://github.com/KEINOS/Mastodon_StreamingAPI_Parser) @ GitHub
- Package release: [keinos/mastodon-streaming-api-parser](https://packagist.org/packages/keinos/mastodon-streaming-api-parser) @ Packagist

Contribution
------------

[](#contribution)

- Issues
    - Throw an issue at: [https://github.com/KEINOS/Mastodon\_StreamingAPI\_Parser/issues](https://github.com/KEINOS/Mastodon_StreamingAPI_Parser/issues)
    - If the issue is a bug, then please provide a simple example that are reproducible.
    - If the issue is a feature request, then also provide a simple example with the results you wish, so we can create a test before implementing your feature.
- PR (Pull Request)
    - Please **PR to the `padawan` branch**. After the CI tests/reviews, then merged to `master` branch it will ;-)
    - For more see: [CONTRIBUTE.md](https://github.com/KEINOS/Mastodon_StreamingAPI_Parser/blob/master/CONTRIBUTE.md)
- Rules
    - Be nice, be happy and stay safe.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

Established project with proven stability

 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

Every ~2 days

Total

6

Last Release

2170d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11840938?v=4)[KEINOS](/maintainers/KEINOS)[@KEINOS](https://github.com/KEINOS)

---

Top Contributors

[![KEINOS](https://avatars.githubusercontent.com/u/11840938?v=4)](https://github.com/KEINOS "KEINOS (33 commits)")

---

Tags

mastodonmastodon-apiphpphp7php8

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/keinos-mastodon-streaming-api-parser/health.svg)

```
[![Health](https://phpackages.com/badges/keinos-mastodon-streaming-api-parser/health.svg)](https://phpackages.com/packages/keinos-mastodon-streaming-api-parser)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19139.2M47](/packages/mck89-peast)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9843.5k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

45153.1k6](/packages/jstewmc-rtf)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

113.2k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

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