This section covers two open source packages freely available from the Internet to protect the PHP scripts on your dedicated server: bcompiler and bencoder. You can develop the source scripts on a secure local test server and deploy only the binary bytecode files on a production server using these free tools.

bcompiler is designed as a PHP extension module. It is an open source package that converts PHP scripts into bytecode files. In general, it can help improve script performance by about 30% when using bytecodes in uncompressed form only. However, uncompressed bytecodes can be up to fives times larger than the original source code. Bytecode compression reduces disk space at the expense of having more cpu resources consumed to perform the decompression. bcompiler also does not do any bytecode optimization. However, these issues become trivial or irrelevant when a bytecode cache is used (see the next section on APC).

In terms of code protection, it is safe to say that it would be impossible to recreate the exact source code that it was built from. Without the structure of the source code visible, it would effectively be useless to use the bcompiler bytecodes to recreate and modify a function or an object class. It is still possible to retrieve data from a bcompiled bytecode file. It is prudent to have additional measures to protect private data such as login passwords in case these items are visible in the data section of the bytecode file.

bencoder is a command-line interface to automate the encoding task using bcompiler. It has the option to generate the bytecode files using bzip2 compression. These open source packages are freely available from the Internet. Use the search keywords: bcompiler, bencoder to obtain the latest version from the search result.

This section discusses in details the following topics.

  • Build and install bcompiler as a PHP extension. If you are not familiar with building a package from source on Linux platform, or just want to skip the build step, this condensed guide supplies the pre-built bcompiler versions for Fedora, Centos, FreeBSD, and Ubuntu platforms.

  • Example scripts to generate bytecode file manually from PHP scripts with and without using compression.

  • Examples on how to use the bencoder tool to compile individual files or a directory.