|Classes of Vallo Reima||>||PHP Application Packer||>||README.md||>||Download|
PHP Application Packer
PackApp.php is a complete solution to pack your application's project files into the delivery package. The source code is minified and obfuscated, impeding unauthorized use.
The target audience: ISVs, freelancers, developers, resellers, all who need a lightweight utility to turn the project into the delivery package. The solution is oriented to the PHP applications, but can be used for the front-end projects too.
There are many minifiers, obfuscators, encoders around. Some commercial encoders are very good, but rather expensive and may require system extensions. The others are limited with a single source type only. The Packer is a handy integrated solution.
How it works
PackApp.php packs the project files: minifies the source (html, css, js, json, php, xml), obfuscates the code (js, php) and compresses the result files. The source can be either a single file or a folder which may have sub-folders. The destination is a packed file or a folder with the packed files. The ZIP archives are handled also: folder-to-zip, zip-to-folder, zip-to-zip.
The Packer passes the source to according minify plugin depending on the file type. The css and js that detected inside the html are minified too. The html, css and js are looked for the embedded php to minify (except obfuscated js). You can create the user plugins for more file types.
The js and php code can be obfuscated to inhibit its unauthorized use. The reverse engineering of the packed code becomes too expensive. The identifiers replacement algorithm used by the Packer is more protective than trivial applying of the base64_encode and eval. However, you must follow certain naming rules to avoid the renaming conflicts. The php obfuscation is supported by the standard edition.
There are several options to control the processing. Use them for specific cases and rely on defaults mostly. Launch the Packer via the GUI or instantiate and call directly. Various statistics are returned about the processing results. You can display and/or save this data.
The Packer has the free and extended versions. Free version minifies the source and can be launched via instantiation only.
Extended version includes also the GUI and requires the setup (license registration) before using. The extended version has the following editions:
You can obtain the extended version from [here].
The program requires PHP 5.4+. Start it from your script via GUI (except free version) or instantiation (see The package).
The starter script must be in the same directory with the PackApp.php:
A) Launching the GUI:
B) Instantiation and invocation:
$obj = new PackApp( [$lvl [,$opt]] );
$obj->Pack( $old [,$new [,$rpl]] );
$lvl - processing level, the sum of the following integers:
$opt - the options array:
PHP obfuscation options:
$old - source file/folder/archives
$new -- destination (default by $old value suffixed by sfx option value)
$rpl -- replace destination if exists (default by false)
The $obj->Pack() returns the results associative array:
You can display and/or save the statistics. See example.php about the using.
The files are minified by default and obfuscated (js, php) if required. The php templates are packed for the html, js, css, php. The source file is processed when its type matches one of the following (wildcards allowed);
The rest of the files are simply copied or skipped. Use the pgn option for additional types (see below). The folder or archived source is saved to the destination folder or archived depending on the $new parameter.
The source files of relevant file type are minified by removing the comments, whitespaces and linebreaks. The \htm\ files are checked for the style and script tags which content is minified too. The files (except xml) are checked also for the php tags to pack their content.
The package includes the plugins to minify according sources (see The package). You can define your own plugins for additional file types with the pgn option:
['pgn' => ['type' => flag]]
$obj = new PackApp(1, ['pgn' => ['sql' => false]]);
Place your plugin class into the plugins folder. Make it callable via static minify method like here:
Please [contact] if you would like to include your own plugin(s) into the package.
The standard edition with the PackAppO add-on is required for the PHP obfuscation. It's recommended to follow certain naming rules in the planning and coding stage already to avoid the renaming conflicts (see below).
The php source is processed in two passes. 1st pass registers the identifiers found from the code during the minifying. 2nd pass performs cross-file renaming of the identifiers registered by 1st pass. The following identifiers can be replaced depending on the obf option:
The replacement can be case-insensitive (except variables/properties, heredocs/nowdocs, class constants).
Use the identifiers exclusion list (exi option) and follow the naming rules to avoid the identifiers' replacement conflicts:
These rules are natural to follow and secure from the identifier name collisions. Use the dbg option to fix the renaming issues in the non-minified obfuscated result.
Unzip the obtained package and upload the files to your selected web directory. Then run example.php. The extended version requires the Setup before exploiting. It launches the installer automatically if not set up yet. Run PackApp.php from the browser to launch the installer directly.
The included example minifies/obfuscates the files from the tests.zip and outputs the result into the tests_pkd folder. A message informs about the result. The statistics collected by the packer are displayed and saved into example.txt.
Make a copy from the example.php and try it with different sources, destinations and options. Run index.php to launch the GUI supplied by an extended version.
The extended version supplies the version updates. The About section of the GUI displays the installation and update information and allows to edit your contact data. Run PackApp.php from the browser and click the Update button to check for the updates directly. Your contact data will be used for important product-related messages only. If your contacts change, please edit.
If the updating fails on any reason then the update.php and update.json files created allow to restore - run update.php.
The plugins folder contains the minifiers adapted from the open source. The addons folder is not included in free version. The files list:
Special thanks to the authors referred. Please [contact] for any questions regarding the Packer.