Skip to content

Command line interface

Cédric Belin edited this page Oct 23, 2025 · 13 revisions

Download and run the latest installer of PHP Minifier from the GitHub releases:
https://github.com/cedx/php-minifier.net/releases/latest

Then, in a terminal, invoke the Belin.PhpMinifier program to find the instances of an executable command:

$ Belin.PhpMinifier --help

Description:
  Minify PHP source code by removing comments and whitespace.

Usage:
  Belin.PhpMinifier <input> [<output>] [options]

Arguments:
  <input>   The path to the input file or directory.
  <output>  The path to the output directory. []

Options:
  -?, -h, --help          Show help and usage information
  --version               Show version information
  -b, --binary            The path to the PHP executable. [default: php]
  -e, --extension         The extension of the PHP files to process. [default: php]
  -m, --mode <Fast|Safe>  The operation mode of the minifier. [default: Safe]
  -q, --quiet             Whether to silence the minifier output.
  -r, --recurse           Whether to process the input directory recursively.

For example:

Belin.PhpMinifier path/to/source/folder path/to/destination/folder
# Minifying: MyClass1.php
# Minifying: subfolder/MyClass2.php
# ...

Options

--binary

The minifier relies on the availability of the PHP executable on the target system. By default, the minifier will use the php binary found on the system path.
If the minifier cannot find the default php binary, or if you want to use a different one, you can provide the path to the php executable by using the binary option:

Belin.PhpMinifier "--binary=C:\Program Files\PHP\php.exe" path/to/source/folder

--extension

By default, the minifier will process all files with the .php extension. If your PHP scripts use a different file extension, you can specify another extension to process by using the extension option:

Belin.PhpMinifier --extension=php8 path/to/source/folder

--mode

The minifier can work in two manners, which can be selected using the mode option:

  • the Safe mode: as its name implies, this mode is reliable. But it is also slow as it spawns a new PHP process for every file to be processed. This is the default mode, and the preferred one for processing a single PHP file.
  • the Fast mode: as its name implies, this mode is faster, but it is not always reliable. It spawns a PHP web server that processes the input files, but on some systems this fails.
Belin.PhpMinifier --mode=Fast path/to/source/folder

Tip

The command line defaults to the Safe mode, but you should really give a try to the Fast one.
The difference is very noticeable with large file sets.

--quiet

By default, the minifier prints to the standard output the paths of the minified scripts. You can disable this output by setting the quiet option:

Belin.PhpMinifier --quiet path/to/source/folder

--recurse

By default, the minifier will only process files located at the root of the input folder. To also process all subfolders and files recursively, set the recurse option:

Belin.PhpMinifier --recurse path/to/source/folder
Clone this wiki locally