Skip to content

Fetch PHP

Write fetch() in PHP

A modern HTTP client that mirrors the JavaScript fetch API while staying native to PHP 8.3+. Compose requests fluently, run async flows, and ship production-grade HTTP without the ceremony.

PHP 8.3+ PSR-7/18/3 RFC 7234 Cache Async Helpers
Latest: v1.xGitHub StarsMIT License

Quickstart

Install and ship in minutes

$composer require jerome/fetch-php
  • Drop-in global fetch() helper
  • Async helpers included
  • PSR compliant out of the box

Trusted by PHP teams

Fetch PHP is designed for teams shipping APIs, SaaS backends, and internal tools who want a modern HTTP experience without sacrificing PHP standards.

Internal API platformsSaaS backendsLaravel + Symfony servicesCLI automationEdge proxiesData pipelines

Why Fetch PHP

Modern DX, serious production guarantees

Familiar API

Write requests in PHP the same way you do in JavaScript with fetch(), async, and await.

Promise-Based Async

Promise-first API with then(), catch(), finally(), and helpers for concurrency.

Fluent Interface

Chain config and requests for readable, composable HTTP code.

Helper Functions

Global helpers like fetch(), get(), post() for quick calls.

PSR Compatible

Implements PSR-7 (HTTP Messages), PSR-18 (HTTP Client), and PSR-3 (Logging) standards.

Powerful Responses

Rich response helpers for json(), text(), array(), object(), and status checks.

RFC 7234 Caching

Sync-only cache with ETag/Last-Modified revalidation, stale-while-revalidate, and stale-if-error support.

Pooling & HTTP/2

Shared connection pooling, DNS cache, and optional HTTP/2 with validation and stats for debugging.

Debug & Profiling

Unified debug snapshots and optional profiler with timing, memory, and connection stats; configurable log level.

Copy/paste ready

Same mental model as JavaScript

Use the Matrix async helpers to keep promise-based workflows familiar. The response helpers map directly to fetch(), so JSON parsing feels identical.

  • Promise chaining or async/await
  • Fluent request builder
  • Test utilities built-in
js

const response = await fetch('https://api.example.com/users');const users = await response.json(); if (!response.ok) {  throw new Error('Request failed');} render(users);

Performance & compatibility

Designed for production from day one

Exponential

Retry backoff

RFC 7234

Caching

PSR-7/18/3

Standards

Built on Guzzle

Proven HTTP engine with retries, middleware, and transport control.

Connection Pooling

Reusable sockets and DNS cache for lower latency across requests.

HTTP/2 Ready

Optional HTTP/2 for faster multiplexed connections when curl supports it.

Observability

Debug snapshots, structured logging, and profiler hooks built-in.

DX highlights

Built for real-world PHP teams

  • Type-safe enums for methods, content types, and status codes.
  • Mock server and request recording for deterministic testing.
  • Global client configuration for consistent defaults.
  • Response helpers that mirror fetch().

Next steps

Install, then explore the guide

$composer require jerome/fetch-php
Read the Quickstart

Ready to ship?

Fetch PHP gives your team a clean HTTP foundation

Install with Composer, then dive into the guide for async patterns, retries, and advanced configuration.

$composer require jerome/fetch-php

Released under the MIT License. A modern HTTP client for PHP developers.