PHPackages                             atk14/url-fetcher - 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. atk14/url-fetcher

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

atk14/url-fetcher
=================

Class providing methods to make http requests

v1.8.10(1w ago)046.4k↑29.3%6MITPHPPHP &gt;=5.6CI passing

Since Jan 24Pushed 1w ago2 watchersCompare

[ Source](https://github.com/atk14/UrlFetcher)[ Packagist](https://packagist.org/packages/atk14/url-fetcher)[ Docs](https://github.com/atk14/Translate)[ RSS](/packages/atk14-url-fetcher/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (36)Used By (6)

UrlFetcher
==========

[](#urlfetcher)

[![Tests](https://github.com/atk14/UrlFetcher/actions/workflows/tests.yml/badge.svg)](https://github.com/atk14/UrlFetcher/actions/workflows/tests.yml)

UrlFetcher is a PHP class providing methods to make HTTP requests.

- GET, POST, PUT, DELETE requests
- HTTPS with SSL peer verification
- HTTP Basic Authentication
- Automatic redirect following
- Proxy support
- GZIP content decoding
- Configurable timeouts

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

[](#installation)

```
composer require atk14/url-fetcher

```

Basic usage
-----------

[](#basic-usage)

```
$fetcher = new UrlFetcher("http://www.example.com/content.dat");

if(!$fetcher->found()){
  echo $fetcher->getErrorMessage();
  exit(1);
}

$content = $fetcher->getContent(); // returns StringBufferTemporary

$status_code    = $fetcher->getStatusCode();    // e.g. 200
$status_message = $fetcher->getStatusMessage(); // e.g. "OK"
$content_type   = $fetcher->getContentType();   // e.g. "application/pdf"
$charset        = $fetcher->getContentCharset(); // e.g. "UTF-8"
$content_length = $fetcher->getContentLength(); // e.g. "12345"
$filename       = $fetcher->getFilename();      // e.g. "content.dat"

$request_headers  = $fetcher->getRequestHeaders();
$response_headers = $fetcher->getResponseHeaders();

```

HTTP Basic Authentication
-------------------------

[](#http-basic-authentication)

Credentials can be passed directly in the URL:

```
$fetcher = new UrlFetcher("https://username:password@www.example.com:444/private/content.dat");
if($fetcher->found()){
  echo $fetcher->getContent();
}

```

Or set explicitly:

```
$fetcher = new UrlFetcher("https://www.example.com/private/content.dat");
$fetcher->setAuthorization("username", "password");
if($fetcher->found()){
  echo $fetcher->getContent();
}

$fetcher->resetAuthorization(); // clear credentials

```

POST request
------------

[](#post-request)

Array is sent as `application/x-www-form-urlencoded`:

```
$fetcher = new UrlFetcher("https://www.example.com/api/articles/");
if($fetcher->post(["title" => "Sample article", "body" => "Lorem Ipsum..."])){
  echo $fetcher->getContent();
}

```

Raw string body with a custom content type:

```
$fetcher = new UrlFetcher("https://www.example.com/api/articles/");
$fetcher->post($json, ["content_type" => "application/json"]);

```

PUT and DELETE requests
-----------------------

[](#put-and-delete-requests)

```
$fetcher = new UrlFetcher("https://www.example.com/api/articles/123/");
$fetcher->put($json, ["content_type" => "application/json"]);

$fetcher = new UrlFetcher("https://www.example.com/api/articles/123/");
$fetcher->delete();

```

Custom headers
--------------

[](#custom-headers)

Headers passed to the constructor are sent with every request made by the instance:

```
$fetcher = new UrlFetcher("https://www.example.com/", [
  "additional_headers" => ["X-App-Version: 1.2", "Accept: application/json"]
]);

```

Headers passed to `post()`, `put()`, `delete()` or `fetchContent()` are sent only with that single request:

```
$fetcher->post($data, ["additional_headers" => ["X-Request-ID: abc123"]]);

```

Inspecting response headers
---------------------------

[](#inspecting-response-headers)

```
// single header value (case-insensitive)
$type = $fetcher->getHeaderValue("Content-Type"); // "text/html; charset=UTF-8"

// all headers as an associative array
$headers = $fetcher->getResponseHeaders(["as_hash" => true, "lowerize_keys" => true]);
echo $headers["content-type"];

```

Redirections
------------

[](#redirections)

Redirects (301, 302, 303) are followed automatically. The default limit is 5. It can be changed in the constructor:

```
$fetcher = new UrlFetcher("http://www.example.com/", ["max_redirections" => 10]);

// disable redirections entirely
$fetcher = new UrlFetcher("http://www.example.com/", ["max_redirections" => 0]);

```

After a redirect, `getUrl()` returns the final URL:

```
$fetcher = new UrlFetcher("http://www.example.com/old-page/");
$fetcher->getContent();
echo $fetcher->getUrl(); // the final URL after redirection

```

SSL / HTTPS
-----------

[](#ssl--https)

SSL peer verification is enabled by default. It can be disabled for self-signed or expired certificates:

```
$fetcher = new UrlFetcher("https://www.example.com/", [
  "verify_peer"      => false,
  "verify_peer_name" => false,
]);

```

The default can also be changed globally via a PHP constant before including the library:

```
define("URL_FETCHER_VERIFY_PEER", false);

```

Proxy
-----

[](#proxy)

```
$fetcher = new UrlFetcher("http://www.example.com/", [
  "proxy" => "tcp://127.0.0.1:8118"
]);

```

Timeouts
--------

[](#timeouts)

Two separate timeouts can be configured:

- **socket\_timeout** — connection timeout in seconds (default: 5.0)
- **read\_timeout** — time to wait for data after connecting (default: 60.0)

    $fetcher = new UrlFetcher("", \[ "socket\_timeout" =&gt; 3.0, "read\_timeout" =&gt; 10.0, \]);

They can also be changed at any time. Both methods return the previous value:

```
$prev = $fetcher->setSocketTimeout(3.0);
$prev = $fetcher->setReadTimeout(10.0);

```

User-Agent
----------

[](#user-agent)

```
$fetcher = new UrlFetcher("http://www.example.com/", [
  "user_agent" => "MyApp/2.0"
]);

```

UrlFetcherViaCommand
--------------------

[](#urlfetcherviacommand)

`UrlFetcherViaCommand` is a subclass that sends the HTTP request to an external command via stdin and reads the response from stdout. This is useful for testing or simulating HTTP requests inside an application (e.g. ATK14's `scripts/simulate_http_request`).

```
$fetcher = new UrlFetcherViaCommand("nc localhost 80", "http://localhost/content.dat");
if($fetcher->found()){
  echo $fetcher->getContent();
}

```

Licence
-------

[](#licence)

UrlFetcher is free software distributed [under the terms of the MIT license](http://www.opensource.org/licenses/mit-license)

###  Health Score

56

—

FairBetter than 97% of packages

Maintenance98

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity70

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

Recently: every ~71 days

Total

31

Last Release

7d ago

PHP version history (2 changes)v1.0PHP &gt;=5.3.0

v1.8.7PHP &gt;=5.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/974278?v=4)[Jaromir Tomek](/maintainers/yarri)[@yarri](https://github.com/yarri)

---

Top Contributors

[![yarri](https://avatars.githubusercontent.com/u/974278?v=4)](https://github.com/yarri "yarri (130 commits)")

---

Tags

httpurlutilsdownload

### Embed Badge

![Health badge](/badges/atk14-url-fetcher/health.svg)

```
[![Health](https://phpackages.com/badges/atk14-url-fetcher/health.svg)](https://phpackages.com/packages/atk14-url-fetcher)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[league/uri

URI manipulation library

1.1k240.0M392](/packages/league-uri)[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

539238.7M44](/packages/league-uri-interfaces)[jbzoo/utils

Collection of PHP functions, mini classes and snippets for everyday developer's routine life.

8311.6M36](/packages/jbzoo-utils)[aplus/http

Aplus Framework HTTP Library

2371.6M10](/packages/aplus-http)[nette/http

🌐 Nette Http: abstraction for HTTP request, response and session. Provides careful data sanitization and utility for URL and cookies manipulation.

49119.8M601](/packages/nette-http)

PHPackages © 2026

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