Download the PHP package hryvinskyi/magento2-external-media-prefetcher without Composer

On this page you can find all versions of the php package hryvinskyi/magento2-external-media-prefetcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package magento2-external-media-prefetcher

External Media Prefetcher for Magento 2

A Magento 2 module that automatically fetches missing media files from an external source (typically your production site) with SSRF protection, configurable retries/timeouts, an async queue mode, and placeholder-aware filtering so you never persist a CDN's "image not found" body as a real product image.

Description

This module solves the common problem of missing media files in development or staging environments. When a media file is requested but not found locally, the module automatically attempts to download it from a configured external URL. It hooks in at two points:

  1. Magento\MediaStorage\Model\File\Storage\Synchronization::synchronize() — catches requests routed through pub/get.php.
  2. Magento\Catalog\Model\Product\Image::setBaseFile() — catches catalog image helper calls in templates ($imageHelper->init($product, $type)->resize(...)) before Magento falls back to the placeholder.

Requirements

Installation

Configuration

All configuration is stored in app/etc/env.php and can be managed through a dedicated CLI command — no admin UI is involved.

CLI command

Option Description Default
--show Print current values and exit.
--enabled=1\|0 Enable/disable the prefetcher. 0
--url=<base> Base URL of the external media source (e.g. https://cdn.example.com/media/).
--allowed-schemes=https,http Comma-separated URL schemes the validator will allow. https
--async=1\|0 Dispatch downloads via the message queue instead of running inline. 0
--connect-timeout=<s> HTTP connect timeout in seconds. 3
--request-timeout=<s> HTTP request timeout in seconds. 8
--retry-count=<n> Retries on 5xx / 408 / 429 / transport errors. 4xx does not retry. 2
--retry-delay-ms=<ms> Base delay for exponential backoff between retries. 200
--placeholder-hash=<sha256> Manual placeholder SHA-256 (64-char lowercase hex).
--placeholder-length=<bytes> Manual placeholder byte length.
--auto Probe the external URL once and auto-fill placeholder-hash / placeholder-length. Cannot be combined with the manual flags.

Values are validated up-front: boolean flags accept 1/0/true/false/yes/no/on/off, integer flags must be non-negative, and --placeholder-hash must be a 64-char lowercase hex string.

Example: set everything in one call

The --auto flag probes the URL you just passed (no need to run a separate detect step) and persists the resulting placeholder signature alongside the rest of the options.

Direct env.php editing (if you prefer)

How It Works

Sync mode (default)

  1. A request hits a missing media file.
  2. Either plugin fires (Synchronization or Product\Image), cleans the path, and checks the media directory.
  3. Security\UrlValidator asserts the resulting URL: scheme allowlist, FILTER_VALIDATE_URL, and DNS resolution that rejects loopback / private / link-local / reserved IPs (SSRF protection).
  4. FileDownloader requests the file using the configured connect/request timeouts, with exponential-backoff retries on 5xx / 408 / 429 / transport errors. 4xx responses are terminal.
  5. Before writing, the response body is compared against the cached placeholder signature. If it matches, the file is not saved — preventing "placeholder-as-product-image" pollution when the CDN returns a generic fallback image for missing files.
  6. The destination directory is realpath-checked to guarantee it's inside the Magento media directory (path-traversal protection).
  7. The file is written and the request proceeds against the real image.

Async mode

When --async=1 is set, both plugins publish the clean relative path onto the hryvinskyi.external_media_prefetcher.download queue (db connection) instead of fetching inline. The current request still renders the placeholder, but the next request for the same file gets the real image. Start the consumer with:

Placeholder detection

If you don't configure a manual signature, PlaceholderDetector probes the external URL once against a guaranteed-missing path (<base>/catalog/product/__hryvinskyi_emp_probe_<random>.jpg) and caches the {hash, length} result in Magento's app cache (tag HRYVINSKYI_EMP_PLACEHOLDER, TTL 1 day). Negative probes (4xx/5xx/empty) are also cached so we don't hammer the source.

Logging

All module output goes to var/log/external_media_prefetcher.log (a dedicated Monolog channel), including probe results, blocked SSRF attempts, rejected placeholder bodies, and retry attempts.

Security Notes

Testing

Unit test coverage: Config, PathResolver, FileDownloader (happy path, SSRF rejection, placeholder skip, retry on 5xx, no-retry on 404, path-traversal), PlaceholderDetector (override, cache hit/miss, negative cache, probe), UrlValidator (scheme / loopback / private / link-local / public), SynchronizationPlugin (sync + async branches).

Why It's Useful

License

MIT

Author

Volodymyr Hryvinskyi Email: [email protected] GitHub: https://github.com/hryvinskyi


All versions of magento2-external-media-prefetcher with dependencies

PHP Build Version
Package Version
Requires magento/framework Version *
magento/module-media-storage Version 100.4.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hryvinskyi/magento2-external-media-prefetcher contains the following files

Loading the files please wait ...