PHPackages                             dvanderburg/silex-batched-request - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. dvanderburg/silex-batched-request

ActiveLibrary[HTTP &amp; Networking](/categories/http)

dvanderburg/silex-batched-request
=================================

Service provider for batched requests in Silex.

v0.0.3(8y ago)130MITPHPPHP &gt;=5.6.0

Since Jan 18Pushed 7y ago2 watchersCompare

[ Source](https://github.com/dvanderburg/silex-batched-request)[ Packagist](https://packagist.org/packages/dvanderburg/silex-batched-request)[ Docs](https://github.com/dvanderburg/silex-batched-request)[ RSS](/packages/dvanderburg-silex-batched-request/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

Silex Batched Request Service Provider
======================================

[](#silex-batched-request-service-provider)

[![Latest Stable Version](https://camo.githubusercontent.com/7730aa8c139c79754421ca8e2113971d24cebcbf4306126d4616de6811f9be82/68747470733a2f2f706f7365722e707567782e6f72672f6476616e646572627572672f73696c65782d626174636865642d726571756573742f762f737461626c65)](https://packagist.org/packages/dvanderburg/silex-batched-request)[![Total Downloads](https://camo.githubusercontent.com/ae20acac1876237ffc69681bbfadb04719f607934f81d374bfbd582e1ad7ecb4/68747470733a2f2f706f7365722e707567782e6f72672f6476616e646572627572672f73696c65782d626174636865642d726571756573742f646f776e6c6f616473)](https://packagist.org/packages/dvanderburg/silex-batched-request)[![Latest Unstable Version](https://camo.githubusercontent.com/c90b2b605f4bd84243919376a8876156e1cecc98eb97999f3820e82c81de5d30/68747470733a2f2f706f7365722e707567782e6f72672f6476616e646572627572672f73696c65782d626174636865642d726571756573742f762f756e737461626c65)](https://packagist.org/packages/dvanderburg/silex-batched-request)[![License](https://camo.githubusercontent.com/17b7b9c7a695364eecd778344995b0c8975a149cd9a69d034bea9bbd008b8047/68747470733a2f2f706f7365722e707567782e6f72672f6476616e646572627572672f73696c65782d626174636865642d726571756573742f6c6963656e7365)](https://packagist.org/packages/dvanderburg/silex-batched-request)

Silex service provider to perform batched requests. Usage and implementation roughly based on [making batch requests](https://developers.facebook.com/docs/graph-api/making-multiple-requests) with Facebook's Graph API.

Batching requests allows you to send multiple requests at once, allowing you to perform multiple operations in a single HTTP request. Each request in the batch is processed in sequence unless dependencies are specified.

Requests within the batch can list dependancies on other requests within the batch, and access their responses via JSONP syntax. Again, similar to Facebook's Graph API. Using [JSONP syntax](https://code.google.com/archive/p/jsonpath/), a one request in the batch can use the response from another request in the batch. Once all requests have been completed, an array of responses will be returned and the HTTP connection closed.

Specifying dependancies allows a one request in the batch to utilize the response from another request in the batch. This is achieved using [JSONP](https://en.wikipedia.org/wiki/JSONP) syntax. More information is provided in the [Usage and Examples](#Usage-and-Examples) section.

Built and tested on PHP 5.6, compatible with Silex version 2.

Dependancies
------------

[](#dependancies)

- **PHP &gt;=5.6** Built and tested on PHP 5.6
- **Silex ~2.0** Originally built using Silex version 2.0.4 ()
- **FlowCommunications/JSONPath ~0.3.4** Accommodates JSONP parsing for specifying dependancies ()

Installation and Setup
----------------------

[](#installation-and-setup)

Install the package via [composer](https://getcomposer.org/).

```
composer install dvanderburg/silex-batched-request
```

Register the service provider as part of your application bootstrap process.

```
$app->register(new Dvanderburg\BatchedRequest\BatchRequestServiceProvider(), array(
	'batchrequest.url' => "batch"	// this is the default value
));
```

Service Provider Configuration
------------------------------

[](#service-provider-configuration)

The service provider can be configured to determine which URL to process batched requests with. The default is `/batch/`, meaning to send a batched request you would POST to something like `http://localhost/batch/`. This can be customized, including set the the web root by specifying `/` for `batchrequest.url`.

Simple Batched Requests
-----------------------

[](#simple-batched-requests)

Send a basic batched request by sending an HTTP post to the url you configured the service provider with (/batch/ by default). This example will perform two GET requests and a POST, returning an array of responses. If sending in form data via the body parameter you will need to specify the content type(application/x-www-form-urlencoded or application/json).

HTTP POST Example:

```
POST /batch HTTP/1.1
Content-Type: application/json
include_headers: true,
batch: [
	{ "method": "GET",	"relative_url": "/products/1?one=1&two=2&three=3" },
	{ "method": "GET",	"relative_url": "/users/?ids=larry,jill,sally" },
	{ "method": "POST",	"content-type": "application/x-www-form-urlencoded", "name": "create-user", "relative_url": "/users/?username=john" "body": "password=admin"},

```

JQuery XHR Example:

```
$.ajax({
	method: "POST",
	dataType: "json",
	data: {
		include_headers: true,
		batch: [
			{ "method": "GET",	"relative_url": "/products/1?one=1&two=2&three=3" },
			{ "method": "GET",	"relative_url": "/users/?ids=larry,jill,sally" },
			{ "method": "POST",	"content-type": "application/x-www-form-urlencoded", "name": "create-user", "relative_url": "/users/?username=john" "body": "password=admin" },
		]
	}
})
```

For the examples above, the expected response format would be:

```
[
	{
		"code": 200,
		"headers": [ ... ],
		"body": [{ product_id: 1 }, { product_id: 2 }, { product_id: 3 }]
	},
	{
		"code": 200,
		"headers": [ ... ],
		"body": [{ username: "larry" }, { username: "jill" }, { username: "sally" }]
	},
	{
		"code": 200,
		"headers": [ ... ],
		"body": { username: "john" }
	},
]
```

Removing Headers from the Response
----------------------------------

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

Headers can be removed from the response by setting `include_headers` to `false` in the data of the batch HTTP request. If not specified, the default behaviour is to return headers with each response.

Errors
------

[](#errors)

If a specific request in the batch fails its response within the array of responses will contain a non-200 code. However, the actual HTTP request to process the batch will still return a 200-OK.

Specifying Dependencies with JSONP
----------------------------------

[](#specifying-dependencies-with-jsonp)

Sometimes an operation of one request in the batch is dependant on the response of another. This dependancy can be created specifying a name for a request and then accessing the response of that request using JSONP syntax.

The following example retrieves a user's collection of books which are represented with a `book_id`. The book IDs are then used by a second request in the batch to retrieve information about those books.

HTTP POST Example:

```
POST /batch HTTP/1.1
Content-Type: application/json
batch: [
	{ "method": "GET", "name": "get-user-books", "relative_url": "/user_books/?username=larry" },
	{ "method": "GET", "relative_url": "/books/?book_ids={result=get-user-books:$.book_ids.*}" },

```

In the example above, the first request in the batch is named get-user-books and the second request in the batch uses JSONP syntax to extract all the book\_ids from the first request in order to know what books to retrieve.

If a request is a dependancy of another request and fails, it will cause the request which is dependant on it to also fail. In the above example if the get-user-books request fails, the request to retrieve books will also fail.

Limitations
-----------

[](#limitations)

Batched requests are processed after firewall security, meaning you cannot protect individual requests with firewall rules. It is recommended that batched requests are all behind a firewall requiring authentication, or each individual request checks user authentication and permissions.

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 68.8% 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 ~112 days

Total

3

Last Release

3226d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1413980?v=4)[Dave Vanderburg](/maintainers/dvanderburg)[@dvanderburg](https://github.com/dvanderburg)

---

Top Contributors

[![dvanderburg](https://avatars.githubusercontent.com/u/1413980?v=4)](https://github.com/dvanderburg "dvanderburg (11 commits)")[![KevinTse](https://avatars.githubusercontent.com/u/4293482?v=4)](https://github.com/KevinTse "KevinTse (5 commits)")

---

Tags

batch-requestjsonpphpsilexsilex-providerbatchsilex

### Embed Badge

![Health badge](/badges/dvanderburg-silex-batched-request/health.svg)

```
[![Health](https://phpackages.com/badges/dvanderburg-silex-batched-request/health.svg)](https://phpackages.com/packages/dvanderburg-silex-batched-request)
```

###  Alternatives

[eole/sandstone

Silex RestApi with Websockets.

1115.2k1](/packages/eole-sandstone)[oat-sa/tao-core

TAO core extension

66140.1k108](/packages/oat-sa-tao-core)[marcw/buzz-service-provider

Silex ServiceProvider for Buzz Http Library

117.4k1](/packages/marcw-buzz-service-provider)

PHPackages © 2026

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