Download the PHP package belisoful/prado-compression without Composer

On this page you can find all versions of the php package belisoful/prado-compression. 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 prado-compression

prado-compression

Additional Prado ICompressor codecs, each backed by a system command when its PHP extension is absent.

Prado core ships the native-extension compression codecs (gzip, zlib, deflate, bzip2, zstd, brotli) and the negotiation façade, but a core codec is unavailable when its extension is not installed, and core has no xz/LZMA codec at all. This package adds a fallback layer: each codec here prefers the native extension and drops to the standalone command through Prado's TCliCompressorTrait when the extension is missing, so the format keeps working on a machine where the extension was never built. The order is configurable per codec through a backend mode, and the command backend stages data through temporary files, which a shared system must be set up to keep private.

Codecs

Class Format Native backend Command backend
TXzFallbackCompressor xz/LZMA (.xz) xz extension (php-ext-xz) xz
TGzipFallbackCompressor gzip (.gz) zlib extension gzip
TBzip2FallbackCompressor bzip2 (.bz2) bz2 extension bzip2
TZstdFallbackCompressor zstd (.zst) zstd extension zstd
TBrotliFallbackCompressor brotli (.br) brotli extension brotli

Each implements Prado\IO\Compression\ICompressor, so it drops into any code that accepts a codec class:

isAvailable() is true when a backend the codec's mode permits is present; under the default mode that is either backend. The compressed bytes are the standard stream of the format either way, so data compressed on a machine with the extension decompresses on a machine with only the command, and the reverse.

Prado core keeps an inert Prado\IO\Compression\TXzCompressor stub that throws TNotSupportedException; installing this package provides the working codec.

Backend selection

Each codec selects between its two backends through a static BackendMode property that holds a TFallbackCompressorMode value:

Mode Selection
PhpFirst The extension when it is loaded, otherwise the command. The default.
CliFirst The command when it is present, otherwise the extension.
PhpOnly The extension only; the command never runs.
CliOnly The command only; the extension is never used.

The property is per codec class: setting the gzip mode leaves the zstd mode untouched. A subclass of a codec shares the settings of the codec it extends, so setting the mode, staging directory, or output limit on a subclass also changes them on its parent. The setter matches its string case-insensitively and throws TInvalidDataValueException for a value that is not a mode.

The mode routes by availability, and it changes what isAvailable() reports. An "only" mode counts only its named backend, so a codec in PhpOnly mode without its extension is unavailable even when the command is installed, and a call routed to a missing backend throws that backend's TIOException. A "first" mode uses its preferred backend when that backend is present and the other one otherwise.

The default PhpFirst is the selection the codecs made before the property existed, so code written against 1.0 behaves identically.

Securing the command backend

The command backend stages the command's standard input and output through temporary files — by default in PHP's temporary directory (sys_get_temp_dir()), or in the per-codec directory set with setTempDirectory() — so every byte a codec compresses or decompresses through a command is written to disk for the life of the command run. On a single-tenant system with a private staging directory the data stays contained; on a shared or misconfigured system it can leak to other local users:

Set the command backend up safely:

  1. Point the codec at a private staging directory. The static setTempDirectory() property redirects a codec's staging files to a directory owned by the application user, mode 0700, excluded from backups — no php.ini change needed:

    The property is per codec class, and the setting is fail-closed: the directory must exist and be writable when set (TInvalidDataValueException otherwise) and is validated again at every use, so a directory that later disappears or loses its permissions raises a TIOException at the call instead of silently falling back to the shared system directory — the fallback tempnam() itself performs is detected, the escaped file removed, and the call rejected. The two error keys this raises, fallbackcompressor_tempdirectory_invalid and fallbackcompressor_tempdirectory_escaped, are defined in config/errorMessages.txt.

  2. Give PHP a private temporary directory. For codecs left on the default, point sys_temp_dir in php.ini (or the TMPDIR environment variable) at a directory owned by the application user, mode 0700, excluded from backups:

    Under systemd, PrivateTmp=true on the php-fpm service isolates /tmp without a php.ini change.

  3. Run each application as its own system user. Owner-only file modes protect nothing between applications that share a user.

  4. Keep PATH minimal and root-owned. Every directory on the PHP process's PATH should be writable only by root (for example PATH=/usr/bin:/bin). To remove the lookup entirely, subclass the codec and return absolute paths from commands(). The subclass shares the settings of the codec it extends:

    PATH is also what makes a command available. php-fpm's default clear_env=yes empties the environment, so isAvailable() is false for a command-only codec even with the command installed. Set env[PATH] = /usr/bin:/bin in the pool configuration, or use absolute paths as above.

  5. Limit the output of untrusted input. Decompression can expand a small input enormously, and the command writes its output to the staging directory before PHP reads it. Set a limit so a decompression bomb cannot fill the disk:

    A command that passes the limit is stopped and the call raises a TIOException. The size is checked every 10 ms, so the file can pass the limit by what the command writes in that time. The default is no limit. The limit is per codec class and does not apply to the native backend, which writes no files and is bound by memory_limit.

  6. Keep sensitive data off the command path. For data that must never touch disk, install the extension and set the codec to PhpOnly; the mode guarantees the command, and with it the temporary files, is never used:

The native extension backend compresses in memory and writes no files.

The run itself also holds under failure. The command runs without the variables that set its default options (BZIP, BZIP2, GZIP, XZ_DEFAULTS, XZ_OPT, ZSTD_CLEVEL, ZSTD_NBTHREADS), so the environment cannot change the format or level. A staging file that cannot be fully written or read raises a TIOException. A shutdown function removes the staging files of a run ended by a fatal error, such as memory_limit reached while reading a large output; a process killed outright, as by SIGKILL, leaves them behind.

Level fidelity across backends

The two backends always produce a valid, interoperable stream, but they do not always agree on how hard to compress, because a command does not expose every level its library does:

Pass an explicit in-range level when the exact ratio matters.

TBzip2FallbackCompressor is not on that list: it passes the block size to the command explicitly, resolving a level exactly as TBzip2Compressor does, so both backends select the same block size for the same request. bzip2 is deterministic, so with reference bzip2 the two in fact produce byte-identical output; lbzip2 installed as bzip2 writes other valid bytes. TZstdFallbackCompressor is not on it either: levels 20..22 reach the command with --ultra, so both backends honor every level the extension accepts.

The gzip command runs with -n, so equal input gives equal bytes at a level, with no staging file name or time in the header.

Input acceptance across backends

Both backends reject data that is not their format, an empty input, and trailing data after a gzip member, and both read every stream of a concatenated bzip2 file, as pbzip2 and lbzip2 write. This needs a Prado checkout that includes pradosoft/prado#1453; one locked to an earlier dev-master keeps the more lenient core decoding. Two bzip2 cases differ:

So a PhpFirst bzip2 codec may accept a truncated stream that the same codec in CliOnly rejects. Verify a checksum or length of your own where a truncated bzip2 stream must be detected regardless of backend.

Prado integration

The config/ directory holds the package's declarative configuration, mirroring what the framework keeps in framework/classes.php and framework/Exceptions/messages/messages.txt:

File Purpose
config/classMap.json Prado3-style short name to fully qualified name, for Prado::registerClassMap()
config/errorMessages.txt Package error messages, for TException::addMessageFile()

composer.json declares both under extra.prado, so an application installed through Composer needs no wiring: Prado registers every installed extension's error-messages and class-map system-wide before any module initializes. Outside that discovery, the files are registered by hand once at start-up:

registerClassMap() (Prado 4.4+) merges the map into the autoloader, so the codecs resolve by short name the way core classes do — in a configuration file, a template, or Prado::createComponent('TXzFallbackCompressor'). Existing entries win, so a package cannot shadow a core class. Composer's PSR-4 autoloading already covers use by fully qualified name, so the map is only needed for short-name resolution.

config/errorMessages.txt defines the keys the package raises itself: the fallbackcompressor_* keys of the staging directory, staging files, and output limit in securing the command backend. Registering the file makes those exceptions render as readable text; unregistered, an exception still carries its key as the message, so behavior is unaffected. Every other key the codecs surface comes from the core base class and trait they build on and is already in the framework's message file. A registered file overrides the framework's, so a key restated here would replace the framework text; the package defines only its own keys.

Each message is an ICU MessageFormat pattern, as Prado formats every file message with MessageFormatter. A placeholder shown in quotes doubles its apostrophes, ''{0}''; a single '{0}' is ICU-quoted literal text and renders as {0}.

Requirements

Install

Until Prado 4.4.0 is tagged, the framework resolves from its 4.4.x-dev branch alias, so an application with the default stable minimum stability allows it explicitly:

Test

The suite covers both backends of every codec: the native path through compress()/decompress() and the command path directly, so the fallback is tested even on a machine whose extension would otherwise shadow it. The backend modes are tested through fixtures whose command backend returns a marker, so the routing is observable without a command installed. A test that needs a backend that is not installed skips.

Line coverage of src/ is 100%. Branch coverage (php -d memory_limit=1G vendor/bin/phpunit --path-coverage --coverage-text) is complete for every branch a machine can reach: the native arm of a codec runs only where its extension is loaded (the xz native arm runs through a fixture standing in for the extension), and two artifacts of the tooling remain even then — Xdebug enumerates short-circuit paths that cannot occur, and php-code-coverage merges the per-class copies of a trait method under one record, which can under-report an arm the tests demonstrably execute.


All versions of prado-compression with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
pradosoft/prado Version ^4.4@dev
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 belisoful/prado-compression contains the following files

Loading the files please wait ...