PHPackages                             batopa/chirp - 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. [Database &amp; ORM](/categories/database)
4. /
5. batopa/chirp

ActiveLibrary[Database &amp; ORM](/categories/database)

batopa/chirp
============

Cache for Twitter using MongoDB

v1.1.0(7y ago)1201MITPHPPHP &gt;=5.6

Since Feb 29Pushed 7y ago1 watchersCompare

[ Source](https://github.com/batopa/chirp)[ Packagist](https://packagist.org/packages/batopa/chirp)[ Docs](https://github.com/batopa/chirp)[ RSS](/packages/batopa-chirp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (6)Used By (0)

Chirp
=====

[](#chirp)

[![Software license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/batopa/chirp/master/LICENSE)[![Build Status](https://camo.githubusercontent.com/92d85eeff26223515f64e9b71692864beebd8ed0837508d4587ed7e39a5c0509/68747470733a2f2f7472617669732d63692e6f72672f6261746f70612f63686972702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/batopa/chirp)[![codecov.io](https://camo.githubusercontent.com/256f69050a8bd7447e4e51529577704ea72fe47369dbd2c724c94c745b4a08e8/68747470733a2f2f636f6465636f762e696f2f6769746875622f6261746f70612f63686972702f636f7665726167652e7376673f6272616e63683d6d6173746572)](https://codecov.io/github/batopa/chirp?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/c6afec82dbb481d1d7ba3cd2108dcb466526bd34cfd6220e128226cff449b1ca/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6261746f70612f63686972702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/batopa/chirp/?branch=master)[![Code consistency](https://camo.githubusercontent.com/5b82ecffc8c6b7144c12c750fe01cd255de8006158f72bb738c0bae6f3b30299/687474703a2f2f737175697a6c6162732e6769746875622e696f2f5048505f436f6465536e69666665722f616e616c797369732f6261746f70612f63686972702f67726164652e737667)](http://squizlabs.github.io/PHP_CodeSniffer/analysis/batopa/chirp)[![Latest Stable Version](https://camo.githubusercontent.com/344204ac8a33b8cccb237335649a2aca80bfcd629ccd2d446e3a1f5b4ea4c1c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6261746f70612f63686972702e737667)](https://packagist.org/packages/batopa/chirp)

A PHP library to use MongoDB as cache engine for Twitter.

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

[](#requirements)

**Chirp** requires [MongoDB](https://www.mongodb.org) and [MongoDB PHP Driver](http://php.net/manual/en/set.mongodb.php)

Install
-------

[](#install)

Using [composer](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx) installed globally

```
composer require batopa/chirp
```

Basic use
---------

[](#basic-use)

```
require 'vendor/autoload.php';

use Bato\Chirp\Chirp;

// set your Twitter auth conf
$twitterAuth = [
    'oauth_access_token' => 'xxx',
    'oauth_access_token_secret' => 'yyy',
    'consumer_key' => 'www',
    'consumer_secret' => 'zzz'
];

$mongoDbAuth = [
    // the MongoDB database name to use
    'db'  => 'chirp',
    // the MongoDB connection uri. Do not set to use default
    // 'uri' => 'mongodb://user:password@localhost:27017'
];

// instantiate Chirp with Twitter auth and MongoDB conf
$chirp = new Chirp($twitterAuth, $mongoDbAuth);

// Perform Twitter API request GET statuses/user_timeline of @batopa user
// and save tweets in MongoDB
$result = $chirp->write('statuses/user_timeline', [
    // contains parameter used to build the query string
    'query' => [
        'screen_name' => 'batopa'
    ]
]);

// $result will be an array as
// [
//     'saved' => [array of tweets saved],
//     'read' => [array of tweets returned from Twitter API]
// ]

// read data saved previously
$tweets = $chirp->read('statuses/user_timeline');
```

The MongoDB collection used is based on Twitter request endpoint replacing `/` with `-` character, so:

- `statuses/user_timeline` request become `statuses-user_timeline` collection name
- `/statuses///home_timeline//` request become `statuses-home_timeline` collection name

Advanced use
------------

[](#advanced-use)

### Saving

[](#saving)

You can just save some of tweets returned

```
// Save only tweets under some conditions
$chirp->write('statuses/user_timeline', [
    // contains parameter used for build the query string
    'query' => [
        'screen_name' => 'batopa'
    ],
    // save only if '#chirp' or 'cache' are in 'text' key
    'grep' => [
        'text' => ['#chirp', 'cache']
    ],
    // save only if 'entities' is not empty
    'require' => ['entities']
]);
```

`grep` and `require` can be used to traversing the result set

```
$chirp->write('statuses/user_timeline', [
    // contains parameter used for build the query string
    'query' => [
        'screen_name' => 'batopa'
    ],
    // save only if 'user' has the key 'location'
    // populated with a string containing 'IT'
    'grep' => [
        'user.location' => 'IT'
    ],
    // save only if 'entities' has the key 'hashtags' valorized
    'require' => ['entities.hashtags']
]);
```

### Reading

[](#reading)

You can take advantage of MongoDB to filter, sort and manipulate the tweets read, for example

```
// Read data from MongoDB
$chirp->read('statuses/user_timeline', [
    // filter
    [
        'user.screen_name' => 'batopa'
    ],
    // options
    [
        // order by id_str desc
        'sort' => ['id_str' => -1],
        // return only some fields
        'projection' => [
            'created_at' => true,
            'user.screen_name' => true,
            'text' => true,
            'id_str' => true,
            'media_url' => true,
            'entities' => true
        ]
    ]
]);
```

### Using directly MongoDB and Twitter API

[](#using-directly-mongodb-and-twitter-api)

If you need you can get the db or a collection and use them for your purposes

```
// get db
$db = $chirp->getDb();

// get collection
$collection = $chirp->getCollection('statuses/user_timeline');
```

You can also send requests to Twitter API using `Chirp::request()` or getting the instance of [TwitterOAuth](https://twitteroauth.com)

```
$twitter = $chirp->getTwitter();
```

and use directly it.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

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 ~285 days

Total

5

Last Release

2582d ago

Major Versions

v0.3.0 → v1.0.02016-03-19

PHP version history (3 changes)v0.1.0PHP &gt;=5.4

v1.0.0PHP &gt;=5.5

v1.1.0PHP &gt;=5.6

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

apicachemongodbtwitter

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/batopa-chirp/health.svg)

```
[![Health](https://phpackages.com/badges/batopa-chirp/health.svg)](https://phpackages.com/packages/batopa-chirp)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[phpfastcache/phpfastcache

PHP Abstract Cache Class - Reduce your database call using cache system. Phpfastcache handles a lot of drivers such as Apc(u), Cassandra, CouchBase, Couchdb, Dynamodb, Firestore, Mongodb, Files, (P)redis, Leveldb, Memcache(d), Ravendb, Ssdb, Sqlite, Wincache, Xcache, Zend Data Cache.

2.4k5.0M130](/packages/phpfastcache-phpfastcache)[apix/cache

A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache taggging and indexing to Redis, Memcached, PDO/SQL, APC and other adapters.

114542.8k6](/packages/apix-cache)[endeveit/cache

Simple caching library with support for tags.

1711.1k](/packages/endeveit-cache)

PHPackages © 2026

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