PHPackages                             jeroen/file-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. jeroen/file-fetcher

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

jeroen/file-fetcher
===================

Simple file fetching interface

6.1.1(1y ago)6433.1k↑169.8%3[1 issues](https://github.com/JeroenDeDauw/FileFetcher/issues)[1 PRs](https://github.com/JeroenDeDauw/FileFetcher/pulls)11BSD-3-ClausePHPPHP &gt;=7.3CI failing

Since Jul 5Pushed 1y ago3 watchersCompare

[ Source](https://github.com/JeroenDeDauw/FileFetcher)[ Packagist](https://packagist.org/packages/jeroen/file-fetcher)[ Docs](https://github.com/JeroenDeDauw/FileFetcher)[ GitHub Sponsors](https://github.com/JeroenDeDauw)[ RSS](/packages/jeroen-file-fetcher/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (6)Versions (17)Used By (11)

FileFetcher
===========

[](#filefetcher)

[![Build Status](https://camo.githubusercontent.com/ecdecf72abffe476d5d7d007d0add414847d8193dd2a599b7025772559fff349/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f4a65726f656e4465446175772f46696c65466574636865722f63692e796d6c)](https://github.com/JeroenDeDauw/FileFetcher/actions?query=workflow%3ACI)[![codecov](https://camo.githubusercontent.com/ee206a8bcb09c77b1d2abb9c13e3256b26485fab154a3838a617d09ae82208c6/68747470733a2f2f636f6465636f762e696f2f67682f4a65726f656e4465446175772f46696c65466574636865722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/JeroenDeDauw/FileFetcher)[![Type Coverage](https://camo.githubusercontent.com/b5bc23dd83d1455203050586cb81f6067b8eeb387cda197f7a0b336dcf2325f8/68747470733a2f2f73686570686572642e6465762f6769746875622f4a65726f656e4465446175772f46696c65466574636865722f636f7665726167652e737667)](https://shepherd.dev/github/JeroenDeDauw/FileFetcher)[![Psalm level](https://camo.githubusercontent.com/e025da2b849ab0b7329c3a7a39f428cbaf3cfc6afb65ece7810854b65f257097/68747470733a2f2f73686570686572642e6465762f6769746875622f4a65726f656e4465446175772f46696c65466574636865722f6c6576656c2e737667)](psalm.xml)[![Latest Stable Version](https://camo.githubusercontent.com/dab58604f0a41d727c56471984d79e25828dbe6af201e4e44ff4481784f103de/68747470733a2f2f706f7365722e707567782e6f72672f6a65726f656e2f66696c652d666574636865722f762f737461626c65)](https://packagist.org/packages/jeroen/file-fetcher)[![Download count](https://camo.githubusercontent.com/edbd45b777b6a5ebe1ea19a120e2d3920afad36f7d20fdafedbb6685491c5493/68747470733a2f2f706f7365722e707567782e6f72672f6a65726f656e2f66696c652d666574636865722f646f776e6c6f616473)](https://packagist.org/packages/jeroen/file-fetcher)[![License](https://camo.githubusercontent.com/6d08b8fd1b214b7d330812e666812ec3f016ddff0004619e8b40a61a6bc8ab58/68747470733a2f2f706f7365722e707567782e6f72672f6a65726f656e2f66696c652d666574636865722f6c6963656e7365)](LICENSE)

The philosophy behind this library is to provide a very basic interface ([`FileFetcher`](https://github.com/JeroenDeDauw/FileFetcher/blob/master/src/FileFetcher.php)) that is ideal for 95% of network access cases, such as your typical `file_get_contents` call. It explicitly does not try to deal with the more complex cases.

Several basic implementations are provided. These include the test doubles you typically need to test services that use the `FileFetcher` interface. You can easily create an adapter to a more heavy network access library (such as [Guzzle](http://docs.guzzlephp.org/en/latest/)) in your own codebase.

Usage
-----

[](#usage)

```
$fileContent = $fileFetcher->fetchFile($fileLocation);
```

The library provides some trivial implementations of the `FileFetcher` interface at its heart:

- `SimpleFileFetcher`: [Adapter](https://en.wikipedia.org/wiki/Adapter_pattern) around `file_get_contents`
- `InMemoryFileFetcher`: Adapter around an array provided to its constructor
- `ThrowingFileFetcher`: Throws a `FileFetchingException` for all calls
- `NullFileFetcher`: Returns an empty string for all calls
- `StubFileFetcher`: Returns a stub value for all calls
- `CallbackFileFetcher`: Adapter around a callback
- `LazyStubFileFetcher`: Return a lazily retrieved stub value for all calls

It also provides a number of [decorators](https://en.wikipedia.org/wiki/Decorator_pattern):

- `ErrorLoggingFileFetcher`: Logs errors via the [PSR-3 LoggerInterface](https://www.php-fig.org/psr/psr-3/)
- `SpyingFileFetcher`: A [spy (test double)](https://www.entropywins.wtf/blog/2016/05/13/5-ways-to-write-better-mocks/)

Decorators provided by [jeroen/file-fetcher-cache](https://github.com/JeroenDeDauw/file-fetcher-cache):

- `PsrCacheFileFetcher`: Caches file contents via [PSR-16 SimpleCache](https://www.php-fig.org/psr/psr-16/)
- `CachingFileFetcher`: Caches file contents. Requires `jeroen/simple-cache` to be loaded

Decorators provided by [jeroen/file-fetcher-stopwatch](https://github.com/JeroenDeDauw/file-fetcher-stopwatch):

- `StopwatchFileFetcher`: Profiles calls using Symfony Stopwatch. Requires `symfony/stopwatch` to be loaded

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

[](#installation)

You can use [Composer](http://getcomposer.org/) to download and install this package as well as its dependencies.

To add this package as a local, per-project dependency to your project, simply add a dependency on `jeroen/file-fetcher` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on FileFetcher 6.x:

```
{
    "require": {
        "jeroen/file-fetcher": "~6.0"
    }
}

```

Development
-----------

[](#development)

Start by installing the project dependencies by executing

```
composer update

```

You can run the tests by executing

```
make test

```

You can run the style checks by executing

```
make cs

```

To run all CI checks, execute

```
make ci

```

You can also invoke PHPUnit directly to pass it arguments, as follows

```
vendor/bin/phpunit --filter SomeClassNameOrFilter

```

Release notes
-------------

[](#release-notes)

### 6.1.1 (2025-02-27)

[](#611-2025-02-27)

- Improved PHP 8.4+ compatibility by explicitly defining nullable types

### 6.1.0 (2022-04-26)

[](#610-2022-04-26)

- Added support for installation with `psr/log` 2.x and 3.x
- Raised minimum PHP version from 7.1 to 7.3
- Improved type documentation

### 6.0.0 (2019-01-17)

[](#600-2019-01-17)

Breaking changes to increase package stability and avoid the need for breaking changes in the future.

- Removed `PsrCacheFileFetcher`, now part of `jeroen/file-fetcher-cache`
- Removed `CachingFileFetcher`, now part of `jeroen/file-fetcher-cache`
- Removed `StopwatchFileFetcher`, now part of `jeroen/file-fetcher-stopwatch`

### 5.0.1 (2019-01-16)

[](#501-2019-01-16)

- `PsrCacheFileFetcher` now ensures cache keys are valid

### 5.0.0 (2019-01-16)

[](#500-2019-01-16)

- Added `PsrCacheFileFetcher`
- Added `StopwatchFileFetcher`
- `jeroen/simple-cache`, which is needed by `CachingFileFetcher` is no longer loaded by default

### 4.5.0 (2018-12-19)

[](#450-2018-12-19)

- Switched License from GPL-2.0-or-later to BSD-3-Clause

### 4.4.0 (2018-05-31)

[](#440-2018-05-31)

- Dropped support for PHP 7.0
- Added `CallbackFileFetcher`
- Added `LazyStubFileFetcher`

### 4.3.0 (2017-06-10)

[](#430-2017-06-10)

- Added `getFirstFetchedUrl` to `SpyingFileFetcher`
- Added `$defaultContent` constructor parameter to `InMemoryFileFetcher`

### 4.2.0 (2017-06-07)

[](#420-2017-06-07)

- Added `StubFileFetcher`

### 4.1.0 (2017-05-11)

[](#410-2017-05-11)

- Added `ThrowingFileFetcher`
- Added `NullFileFetcher`

### 4.0.0 (2017-05-09)

[](#400-2017-05-09)

Breaking changes:

- Added scalar type hints to the `FileFetcher` interface and its implementations
- Added scalar type hints to `FileFetchingException`

Other changes:

- Dropped support for PHP 5.x
- Added `ErrorLoggingFileFetcher`
- Added `SpyingFileFetcher`

### 3.1.0 (2016-01-07)

[](#310-2016-01-07)

- Added `InMemoryFileFetcher`

### 3.0.0 (2015-08-21)

[](#300-2015-08-21)

- Added `FileFetchingException`, which should now be thrown by implementations of `FileFetcher` on error
- The non-public fields and methods of `CachingFileFetcher` are now private rather than protected
- Added PHPCS and PHPMD integration

### 2.0.0 (2014-08-19)

[](#200-2014-08-19)

- Removed `FileFetcher.php` entry point. Autoloading is now done via Composers PSR-4 support.

### 1.0.1 (2013-07-06)

[](#101-2013-07-06)

- Added `SimpleFileFetcher` implementation

### 1.0.0 (2013-07-06)

[](#100-2013-07-06)

- Initial release with `FileFetcher` interface and `CachingFileFetcher` implementation

Links
-----

[](#links)

- [FileFetcher on Packagist](https://packagist.org/packages/jeroen/file-fetcher)
- [Latest version of the readme file](https://github.com/JeroenDeDauw/FileFetcher/blob/master/README.md)

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 95.4% 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 ~304 days

Recently: every ~558 days

Total

15

Last Release

492d ago

Major Versions

1.0.1 → 2.0.02014-08-19

2.0.0 → 3.0.02015-08-21

3.1.0 → 4.0.02017-05-09

4.4.0 → 5.0.02019-01-16

5.0.1 → 6.0.02019-01-17

PHP version history (4 changes)1.0PHP &gt;=5.3.0

4.0.0PHP &gt;=7.0

4.4.0PHP &gt;=7.1

6.1.0PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/451bd4039d530fed8f9c3da91bfa519233a397d2182cdfdcad700f6cfea19b7f?d=identicon)[Jeroen De Dauw](/maintainers/Jeroen%20De%20Dauw)

---

Top Contributors

[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (125 commits)")[![gbirke](https://avatars.githubusercontent.com/u/223326?v=4)](https://github.com/gbirke "gbirke (3 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![KaiNissen](https://avatars.githubusercontent.com/u/5435996?v=4)](https://github.com/KaiNissen "KaiNissen (1 commits)")

---

Tags

httprequestcurlhttp clientstubsinterfacehttp requesttest-doublesfile\_get\_contentsmocksspiesfile fetcherwget

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jeroen-file-fetcher/health.svg)

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

###  Alternatives

[symfony/http-client

Provides powerful methods to fetch HTTP resources synchronously or asynchronously

2.0k338.8M5.0k](/packages/symfony-http-client)[smi2/phpclickhouse

PHP ClickHouse Client

84711.6M81](/packages/smi2-phpclickhouse)[aplus/http-client

Aplus Framework HTTP Client Library

2171.6M1](/packages/aplus-http-client)[eightpoints/guzzle-bundle

Integrates Guzzle 6.x, a PHP HTTP Client, into Symfony. Comes with easy and powerful configuration options and optional plugins.

44512.5M57](/packages/eightpoints-guzzle-bundle)[api-platform/metadata

API Resource-oriented metadata attributes and factories

275.0M219](/packages/api-platform-metadata)[pear/http_request2

Provides an easy way to perform HTTP requests.

784.3M54](/packages/pear-http-request2)

PHPackages © 2026

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