PHPackages                             marmelab/silex-multifetch - 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. marmelab/silex-multifetch

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

marmelab/silex-multifetch
=========================

Silex Provider adding multifetch capabilities to your application

91.8k—0%2PHP

Since Jan 13Pushed 7y ago11 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

  [![archived](https://camo.githubusercontent.com/742c4e1d1cee10950fdbcf8cec4cdfb2f650d7d83c0fe0d065a460c50515f2be/68747470733a2f2f63646e6a732e636c6f7564666c6172652e636f6d2f616a61782f6c6962732f6f637469636f6e732f382e352e302f7376672f617263686976652e737667)](https://camo.githubusercontent.com/742c4e1d1cee10950fdbcf8cec4cdfb2f650d7d83c0fe0d065a460c50515f2be/68747470733a2f2f63646e6a732e636c6f7564666c6172652e636f6d2f616a61782f6c6962732f6f637469636f6e732f382e352e302f7376672f617263686976652e737667) **Archived Repository**
 This code is no longer maintained. Feel free to fork it, but use it at your own risks.  Marmelab Silex Multifetch
=========================

[](#marmelab-silex-multifetch)

Multifetch is a Silex provider which adds multifetch capabilities to any Silex project. Based on [Facebook's Batch Requests philosophy](https://developers.facebook.com/docs/graph-api/making-multiple-requests).

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

[](#installation)

Use Composer to install the package in your project:

```
composer require marmelab/silex-multifetch "~1.0@dev"
```

Enable `HttpFragmentServiceProvider` in your application:

```
$app->register(new Silex\Provider\HttpFragmentServiceProvider());

$app->register(new Marmelab\Multifetch\MultifetchServiceProvider(), array(
    'multifetch.url' => 'multi', // this is the default value
    'multifetch.methods' => array('POST'), // this is the default value
    'multifetch.parallel' => false, // this is the default value
    'multifetch.headers' => true, // this is the default value
));
```

Usage
-----

[](#usage)

Send a request to the route where the provider is listening ('/multi' by default), and pass the requests to be fetched as a JSON object in the request body. For instance, to fetch `/products/1` and `/users` with a single HTTP request, make the following request:

```
POST /multi HTTP/1.1
Content-Type: application/json
{
    "product": "/products/1",
    "all_users": "/users"
}

```

The provider will call both HTTP resources, and return a response with a composite body once all the requests are fetched:

```
{
    "product": {
        "code": 200,
        "headers": [
            { "name": "Content-Type", "value": "application/json" }
        ],
        "body": "{ id: 1, name: \"ipad2\", stock: 34 }"
    },
    "all_users": {
        "code": 200,
        "headers": [
            { "name": "Content-Type", "value": "application/json" }
        ],
        "body": "[{ id: 2459, login: \"paul\" }, { id: 7473, login: \"joe\" }]"
    },
}
```

Any header present in the multifetch request will be automatically added to all sub-requests.

### Request method

[](#request-method)

By default, the '/multi' route listens only for POST requests. However, you can configure the provider to also (or only) accept `GET` requests. To enable it, just set the `multifetch.methods` provider configuration to `array('GET')`.

The provider then reads the query parameters to determine the requests to fetch:

```
GET /multi?product=/product/1&all_users=/users HTTP/1.1

```

If you want to enable both `POST` and `GET` routes, set `array('POST', 'GET')` value a `multifetch.methods` value.

### Parallelize requests

[](#parallelize-requests)

To be able to use parallel fetching feature, you must install `Parallel.php` library. Use Composer to install it:

```
composer require tiagobutzke/phparallel "~0.1"
```

A multifetch request can fetche subrequests in parallel, if you add the `_parallel` parameter:

```
POST /multi HTTP/1.1
Content-Type: application/json
{
    "product": "/products/1",
    "all_users": "/users",
    "_parallel": true
}

```

You can also, if you want, enable parallel fetching for all queries by setting the `'mutltifetch.parallel'` provider parameter to `true`. In that case, if you want to disable parallel fetching for only one query, you can do:

```
POST /multi HTTP/1.1
Content-Type: application/json
{
    "product": "/products/1",
    "all_users": "/users",
    "_parallel": false
}

```

**Warning**: The `parallel` option forks a new thread for each sub-request, which may or may not be faster than executing all requests in series, depending on your usage scenario, and the amount of I/O spent in the subrequests.

### Removing headers from the response

[](#removing-headers-from-the-response)

You may want to remove `headers` from the response for more efficiency. Set the `_headers` parameter to `false` in your query:

```
POST /multi HTTP/1.1
Content-Type: application/json
{
    "product": "/products/1",
    "all_users": "/users",
    "_headers": false
}

```

You can also remove `headers` from the response for all your queries by setting `multifetch.headers` to `false` in the provider configuration.

### Errors

[](#errors)

It's possible that one of your requested operation may throw an error. A similar response will be returned, but with a custom status and body. Successfull requests will be returned, as normal, with a 200 status code.

Here is a response example:

```
POST /multi HTTP/1.1
Content-Type: application/json
{
    "product": "/products/1",
    "all_users": "/non_existing_route",
    "single_user": "/users/brian" // will trigger a 500 error
}

```

```
{
    "product": {
        "code": 200,
        "headers": [
            { "name": "Content-Type", "value": "application/json" }
        ],
        "body": "{ id: 1, name: \"ipad2\", stock: 34 }"
    },
    "all_users": {
        "code": 404,
        "headers": [],
        "body": "{ error: \"No route found for \\\"GET \\\/non_existing_route\\\"\", type: \"NotFoundHttpException\" }"
    },
    "single_user": {
        "code": 500,
        "headers": [],
        "body": "{ error: \"Oops! Something went wrong.\", type: \"InternalServerError\" }"
    },
}
```

Tests
-----

[](#tests)

Run the tests suite with the following commands:

```
make install
make test
```

License
-------

[](#license)

Silex Multifetch is licensed under the [MIT License](LICENSE), courtesy of [marmelab](http://marmelab.com).

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.9% 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.

### Community

Maintainers

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

---

Top Contributors

[![jeromemacias](https://avatars.githubusercontent.com/u/582446?v=4)](https://github.com/jeromemacias "jeromemacias (23 commits)")[![fzaninotto](https://avatars.githubusercontent.com/u/99944?v=4)](https://github.com/fzaninotto "fzaninotto (8 commits)")[![alexisjanvier](https://avatars.githubusercontent.com/u/547706?v=4)](https://github.com/alexisjanvier "alexisjanvier (1 commits)")

### Embed Badge

![Health badge](/badges/marmelab-silex-multifetch/health.svg)

```
[![Health](https://phpackages.com/badges/marmelab-silex-multifetch/health.svg)](https://phpackages.com/packages/marmelab-silex-multifetch)
```

###  Alternatives

[amstaffix/pagination

Simple pagination

46290.4k6](/packages/amstaffix-pagination)[faonni/module-smart-category

SmartCategory module is a base of Smart Categories functionality.

8289.3k3](/packages/faonni-module-smart-category)[sitegeist/silhouettes

Preconfigure property-silhuettes that can be applied to various properties of multiple NodeTypes.

16157.5k](/packages/sitegeist-silhouettes)[michaeljennings/refinery

A php class to refine data into a set format.

129.5k2](/packages/michaeljennings-refinery)

PHPackages © 2026

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