Skip to content
Greg Bowler edited this page Mar 16, 2026 · 11 revisions

The Fetch API is a web standard for making HTTP requests in a promise-based way. If you have used fetch() in the browser, the core idea will already feel familiar: make a request, work with a Response, and choose whether to wait for one request or run many at the same time.

This project brings that workflow to PHP. Behind the scenes it uses cURL (specifically curl_multi for concurrency), but the public API is designed to feel as close to the browser's fetch API as possible.

Why do we need yet another HTTP library?

There is no shortage of HTTP clients in PHP, and if you already have a preferred tool there is no need to replace it. The purpose of this project is to bring the consistency of web standards to your server-side code.

PHP.GT focuses on bringing familiar web standards to server-side PHP. With Fetch, we can use a very similar mental model on both the client and the server:

  • create a request
  • receive a Response
  • process the body as text, JSON or a blob
  • run multiple requests concurrently
  • optionally cancel a request with an abort signal

That makes code easier to move between environments, and easier to reason about when we are building systems that span browser and server code.

What does the library provide?

At the centre of the library is the GT\Fetch\Http object. It provides:

  • fetch() for non-blocking HTTP requests that return a Promise
  • awaitFetch() for a blocking style when we just want the Response
  • wait() to complete all queued requests
  • all() to run all queued requests and resolve when everything has finished

Requests may be configured with familiar fetch-style options such as:

  • method
  • headers
  • body
  • redirect
  • referrer
  • integrity
  • keepalive
  • signal

There is also support for passing a PSR-7 RequestInterface directly to fetch(), which makes interop straightforward if the request has already been built elsewhere in your application.


If you are new to the library, start with the overview. From there we will look at constructing Http objects, making requests, choosing how to wait for them, and using the request options that are currently implemented.

When you want to see complete scripts, take a look at the usage examples page, which mirrors the runnable files in the repository's example/ directory.

Clone this wiki locally