Skip to content
A tool for compiling multiple php (& other) files into a single PHP executable for command line tools.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


A tool for merging multiple php (& other) files into a single PHP file for command line tools. Autoload is handled automatically!


Installation (Linux)

  1. If ~/.local/bin does not exist or is not in the path, run mkdir ~/.local/bin && echo export PATH="$HOME/.local/bin:\$PATH" >> ~/.profile && source ~/.profile

  2. Run wget -O ~/.local/bin/pcan

  3. Run chmod +x ~/.local/bin/pcan

  4. If wget is installed in /usr/bin/wget, PHPCanner can automatically update (just run pcan without any arguments)!

Installation (Windows)

  1. Download pcan (in repository root) to your project's directory.
  2. Prefix all pcan commands with php.


  1. Run pcan init {Project Directory} to create a new project.
  2. Configure pcan.json to your needs (See below).
  3. Run pcan build from within your project folder to build your project. Now you have one single executable!


The pcan.json file contains information necessary to build your project. Every field is explained below.

String name

The name of your project.

String description

The description of your project.

String version

The version number/string for a build.

String license

A brief statement about your project's license, or just the whole license.

String Array contributors

A string array of your project's contributors.

String sourceDirectory

The path to your project's code, relative or absolute.

String entryFunction

The function that will start your project, namespace sensitive, without parentheses. It must have one array parameter for command line arguments. Example: Project\\Program::Main

String outputDirectory

The path the built program will be placed into, relative or absolute.

String outputFile

The name of the final "executable".

PHPCanner class

PHPCanner includes a class PHPCanner in the global namespace to add some basic functionality.

Constant String NAME

The name field set in pcan.json

Constant String DESCRIPTION

The description field set in pcan.json

Constant String VERSION

The version field set in pcan.json

Constant String LICENSE

The license field set in pcan.json

Constant String CONTRIBUTORS

The contributors field set in pcan.json, converted to a string, with newlines (\n or \r\n) as the delimiter.

Constant String PCAN_VERSION

The version of PHPCanner that built the running executable. This can be seen with any PHPCanner-built executable by running {executable} --pcan-version

String Array $files

An array containing the raw (base64) version of included files (see below).

Static Function log(optional String $text) returns void

This function writes the string in $text to the console, and automatically inserts a newline. If tput is available (any *nix system), the text will be properly wrapped to the terminal width, so

This is a block of text. It is long an
d uses many unnecessary words to simul
ate a legitimate long paragraph in ord
er to test word wrapping. This is a te
st for the word wrap feature in the PH
PCanner class. Use it by calling \PHPC
anner::log("text here");! (38 columns)


This is a block of text. It is long
and uses many unnecessary words to
simulate a legitimate long paragraph
in order to test word wrapping. This
is a test for the word wrap feature in
the PHPCanner class. Use it by calling
\PHPCanner::log("text here");! (38

Please note: PHPCanner::end wraps text just like this function.

Static Function end(optional String $message) returns void

This function immediately ends the program and displays the string in $message, if any.

Static Function get_file(String $file_path) returns File Data

This function returns the data from the virtual file at $file_path. See Including Files.

Static Function put_file(String $internal_path, File Data $file_data) returns void

This function stores the data in $file_data into a virtual file located at $internal_path. This can be used to update included files, or create new ones on the fly.
Note: this function is called put_file, not write_file. This only modifies included/virtual files in memory, not permanently.

Static Function get_exec_name() returns String

Returns the path to the currently executing executable. Use in place of __FILE__.

Including Files

PHPCanner allows you to package and include binary files in your final executable. Any non-PHP files located in pcan.json:sourceDirectory will be included automatically. To access a virtual file, call \PHPCanner::get_file({path}), where {path} is the path of the desired file relative to pcan.json:sourceDirectory. For example:

$image = \PHPCanner::get_file('images/alco.png');

Loads the image pcan.json:sourceDirectory/images/alco.png, and stores its binary contents in $image. Another example:

file_put_contents('memo.txt', \PHPCanner::get_file('content/diary.txt'));

Writes out the contents of included file pcan.json:sourceDirectory/content/diary.txt to memo.txt.

Note: All virtual file functions use / as the directory separator. If you pass Windows separators (\) into the function, they will be automatically converted to /.

Side note: PHPCanner::$files contains the raw base64 data of every included file, if you wish to manipulate it. PHP code files follow the naming style: php::{namespace}/{class name}

Namespace Limitations

  • Due to the nature of PHPCanner, all code must be in a named namespace.
  • There may only be one namespace per file.
  • There may only be one class per file.
You can’t perform that action at this time.