PHPackages                             vregistry/packapp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. vregistry/packapp

ActiveLibrary

vregistry/packapp
=================

PackApp.php utility to create packages of project files for distribution by minifying, obfuscating, zipping the source code

0.1.4(9y ago)383217[2 issues](https://github.com/hareko/php-application-packer/issues)BSDPHPPHP &gt;=5.4.0

Since Apr 16Pushed 8y ago8 watchersCompare

[ Source](https://github.com/hareko/php-application-packer)[ Packagist](https://packagist.org/packages/vregistry/packapp)[ Docs](https://github.com/hareko/php-application-packer)[ RSS](/packages/vregistry-packapp/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)DependenciesVersions (2)Used By (0)

PHP Application Packer
======================

[](#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
------------

[](#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.

Versioning
----------

[](#versioning)

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:

- PackApp Lte - lite edition; minifies the source (html, css, js, json, php, xml) and obfuscates the JavaScript code.
- PackApp Std - standard edition; supplies the lite functionality and obfuscates the PHP code.

You can obtain the extended version from [here](http://vregistry.com).

The usage
---------

[](#the-usage)

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*:

**require('PackApp.php');**

A) Launching the GUI:

**echo PackApp::Packer();**

B) Instantiation and invocation:

**$obj = new PackApp( \[$lvl \[,$opt\]\] );**

**$obj-&gt;Pack( $old \[,$new \[,$rpl\]\] );**

### The parameters

[](#the-parameters)

**$lvl** - processing level, the sum of the following integers:

- 0 - minify (default)
- *1* - encode JS (Base62, shrink variables)
- *2* - obfuscate PHP (replace identifiers)
- *4* - compact CSS (remove excessive data)

**$opt** - the options array:

- **exf** - array of the folder/file name wildcards to exclude from the packing (default by *\['\*.min.\*'\]*)
- **sbd** - recurse sub-directories (default by *true*)
- **cpy** - copy non-minified files (default by *true*)
- **pgn** - user plugins (see below)
- **sfx** - default destination name suffix (default by *'\_pkd'*)
- **sgn** - signature to prepend to the minified *php/js/css* code (specify empty value to suppress the default); the replacements:
    - *{app}* - Packer name;
    - *{ver}* - Packer version;
    - *{time}* - current UTC time;
- **tml** - time limit in seconds the program is allowed to run (for larger projects, default by *30*)
- **log** - logging level number: 0 - no, 1 - ok only, 2 - all (default by 0)

PHP obfuscation options:

- **ids** - the identifiers replacement flags (in any sequence, lowercase means case-insensitive, default by *'VDHF'*):
    - *V* - variables/properties
    - *D|d* - defined and class constants (d - defined constants only)
    - *H* - heredocs/nowdocs
    - *F|f* - functions/methods
    - *C|c* - classes
    - *T|t* - traits
- **exi** - array of the identifier wildcards to exclude from the obfuscation (added to predefined ones)
- **pfi** - prefix of the replacement identifier (default by *'\_'*)
- **lni** - replacement identifier's left-padding length with zeroes (default by 0 - no padding)
- **dbg** - debugging flag (default by *false*, *true* - don't minify)

**$old** - source file/folder/archives

**$new** -- destination (default by **$old** value suffixed by **sfx** option value)

**$rpl** -- replace destination if exists (default by *false*)

### Return data

[](#return-data)

The **$obj-&gt;Pack()** returns the results associative array:

- **code** - *'ok'* means success; failed otherwise
- **prompt** - brief message about the success/fail/error
- **factor** - the statistics array (success); if string then the installer html (except free version)
- **string** - the statistics text (newline-separated)

You can display and/or save the statistics. See *example.php* about the using.

Packing
-------

[](#packing)

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);

- *\*htm\** - html code (*htm, html, phtml,* ...)
- *css\** - stylesheet
- *js* - JavaScript code
- *json* - json string
- *xml* - xml source
- *php\** - php code
- *inc* - php code

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.

### Minifying

[](#minifying)

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.

### Obfuscating

[](#obfuscating)

The minified source is obfuscated depending on the **$lvl** parameter value. The JavaScript code is packed into the *eval()* statement replacing the original identifiers. The PHP obfuscation requires the standard edition.

Plugins
-------

[](#plugins)

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' =&gt; \['type' =&gt; flag\]\]**

- *type* - source file type, must be in accordance with the class name (for example, *'sql'* requires *PackSQL.php*)
- *flag* - boolean *true* - check for the embedded php code, *false* - bypass check

For example:

*$obj = new PackApp(1, \['pgn' =&gt; \['sql' =&gt; false\]\]);*

Place your plugin class into the *plugins* folder. Make it callable via static *minify* method like here:

```
...
public static function minify($source, $options = []) {
  $min = new self($options);
  return $min->process($source);
}
...

```

Please [contact](mailto://vallo@vregistry.com) if you would like to include your own plugin(s) into the package.

PHP obfuscation
---------------

[](#php-obfuscation)

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:

- variables/properties
- constants (class and defined ones)
- heredocs/nowdocs
- functions/methods
- classes
- traits

The replacement can be case-insensitive (except variables/properties, heredocs/nowdocs, class constants).

### PHP identifiers

[](#php-identifiers)

Use the identifiers exclusion list (**exi** option) and follow the naming rules to avoid the identifiers' replacement conflicts:

1. Be careful with the variable variables (*$$var*) or add their names to the exclusion list (see example).
2. Don't use the variable names that are the same as any (system) object property name used in the application.
3. The user constant name must not coincide with any system constant name used in the application.
4. The element name which value is got via \_\_get/\_\_set magic methods from the array/object or is computed, must not be the same as any variable/property name used in application.
5. Don't obfuscate the class/trait names which to be autoloaded, and class/method/function names specified in the callbacks, like *call\_user\_func('myclass','mymethod')*.
6. The identifiers prefixed by *'\_\_'* are not obfuscated. You can use this for your identifiers exclusion too.
7. Prefix your identifiers or add to exclusion list, if necessary, to follow (2,3,4,5).
8. Be careful with the case-insensitive names of the functions, classes, traits and defined constants.
9. Sample naming conventions:
    - variables, properties, constants - in camelCase;
    - heredocs, nowdocs - in UPPERCASE;
    - functions, methods, classes, traits - in PascalCase;

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.

Installation
------------

[](#installation)

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.

### Updates

[](#updates)

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 package
-----------

[](#the-package)

The *plugins* folder contains the minifiers adapted from the open source. The *addons* folder is not included in free version. The files list:

- *PackApp.php* - applications packer class
- *PackApp.log* - packer log (created dynamically)
- *addons/.htaccess* - deny access from outside
- *addons/PackAppO.php* - obfuscation extension class
- *addons/PackAppS.php* - services class
- *addons/PackAppS.json* - configuration settings
- *plugins/PackCSS.php* - stylesheets minifier class by [Tubal Martin](https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port)
- *plugins/PackHTM.php* - html's minifier class by [Stephen Clay](https://github.com/mrclay/minify)
- *plugins/PackJS.php* - js minifier class by [Ryan Grove](https://github.com/rgrove/jsmin-php) and js compressor class by [Nicolas Martin](http://joliclic.free.fr/php/javascript-packer/en/), originally by *Dean Edwards*
- *plugins/PackJSON.php* - json minifier class by [Tiste](https://github.com/T1st3/php-json-minify), originally by [Kyle Simpson](https://github.com/getify)
- *plugins/PackPHP.php* - php minifier class, adjusted from the algorithm by [GelaMu](http://php.net/manual/en/function.php-strip-whitespace.php)
- *plugins/PackXML.php* - xml minifier class by [Vallo Reima](https://github.com/hareko/php-merge-xml)
- *example.php* - instantiation sample script
- *tests.zip* - test files for the usage sample
- *index.php* - GUI starter script (except free version)

Special thanks to the authors referred. Please [contact](mailto://vallo@vregistry.com) for any questions regarding the Packer.

ChangeLog
---------

[](#changelog)

- 16 Aug 2016
    - Compact CSS option ($lvl parameter)
    - GUI result download
- 19 Oct 2016
    - ZipArchive PHP7 compatibility

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3316d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d36bf0a3df1c41c0f7cd65312cb63103afef04f7615685f45b23b34752536d03?d=identicon)[hareko](/maintainers/hareko)

---

Top Contributors

[![hareko](https://avatars.githubusercontent.com/u/5305047?v=4)](https://github.com/hareko "hareko (91 commits)")

---

Tags

minifyminifierobfuscateobfuscatorobfuscatingminifying

### Embed Badge

![Health badge](/badges/vregistry-packapp/health.svg)

```
[![Health](https://phpackages.com/badges/vregistry-packapp/health.svg)](https://phpackages.com/packages/vregistry-packapp)
```

###  Alternatives

[matthiasmullie/minify

CSS &amp; JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.

2.0k30.5M336](/packages/matthiasmullie-minify)[fitztrev/laravel-html-minify

Minifies the HTML output of Laravel 4 applications

414211.4k](/packages/fitztrev-laravel-html-minify)[tholu/php-packer

A PHP version of Packer, JavaScript obfuscation library originally created by Dean Edwards

137441.2k5](/packages/tholu-php-packer)[ph-7/obfuscator

 Simple and effective Obfuscator PHP class (this is not a stupid base64 encoding script, but a real and effective obfuscation script)

3762.5k](/packages/ph-7-obfuscator)[sensiolabs/minify-bundle

Assets Minifier (CSS, JS) for Symfony &amp; Minify integration in Asset Mapper

5694.9k1](/packages/sensiolabs-minify-bundle)[pfaciana/tiny-html-minifier

Minify HTML in PHP with just a single class

1095.9k4](/packages/pfaciana-tiny-html-minifier)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
