PHP: PHP bytecode Compiler - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

bcompiler_load_exe bcsub

Last updated: Fri, 26 Jan 2007

view this page in

# VIII. PHP bytecode Compiler

# Введение

Внимание
Это расширение является ЭКСПЕРИМЕНТАЛЬНЫМ. Поведение этого расширения, включая имена его функций и относящуюся к нему документацию, может измениться в последующих версиях PHP без уведомления. Используйте это расширение на свой страх и риск.

Bcompiler was written for several reasons:

To encode entire script in a proprietary PHP application
To encode some classes and/or functions in a proprietary PHP application
To enable the production of php-gtk applications that could be used on client desktops, without the need for a php.exe.
To do the feasibility study for a PHP to C converter

The first of these goals is achieved using the bcompiler_write_header(), bcompiler_write_file() and bcompiler_write_footer() functions. The bytecode files can be written as either uncompressed or plain. To use the generated bytecode, you can simply include it with include or require statements.

The second of these goals is achieved using the bcompiler_write_header(), bcompiler_write_class(), bcompiler_write_footer(), bcompiler_read(), and bcompiler_load() functions. The bytecode files can be written as either uncompressed or plain. The bcompiler_load() reads a bzip compressed bytecode file, which tends to be 1/3 of the size of the original file.

To create EXE type files, bcompiler has to be used with a modified sapi file or a version of PHP which has been compiled as a shared library. In this scenario, bcompiler reads the compressed bytecode from the end of the exe file.

bcompiler can improve performance by about 30% when used with uncompressed bytecodes only. But keep in mind that uncompressed bytecode can be up to 5 times larger than the original source code. Using bytecode compression can save your space, but decompression requires much more time than parsing a source. bcompiler also does not do any bytecode optimization, this could be added in the future...

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, and without the accompanying source code comments. It would effectively be useless to use the bcompiler bytecodes to recreate and modify a class. However it is possible to retrieve data from a bcompiled bytecode file - so don't put your private passwords or anything in it.

# Установка

short installation note:

- You need at least PHP 4.3. for the compression to work

- To install on PHP 4.3 and later at the unix command prompt type pear install bcompiler

- To install on Windows, until the binary package distribution mechanism is finished please search the archives of the pear-general mailing list for pre-built packages. (or send an email to it if you could not find a reference)

- To install on older versions you need to make some slight changes to the build.

- untar the `bcompiler.tgz` archive into `php4/ext`.(Get it directly from PECL http://pecl.php.net/get/bcompiler)

- If the new directory is now called something like bcompiler-0.x, then you should rename it to bcompiler (except you only want to build it as self-contained php-module).

- If you are using versions before PHP 4.3, the you will need to copy the `Makefile.in.old` to `Makefile.in` and `config.m4.old` to `config.m4`.

- run phpize in `ext/bcompiler`

- run ./buildconf in `php4`

- run configure with `--enable-bcompiler` (and your other options)

- make; make install

- that's it.

# Contact Information

If you have comments, bugfixes, enhancements or want to help developing this beast, you can drop me a mail at alan_k@php.net. Any help is very welcome.

add a note User Contributed Notes
PHP bytecode Compiler
cdsheen+bencoder at gmail dot com
25-Jul-2006 05:58
`Here's a script to act as a front-end for bcompiler, which may be very similar to the eA ones:
http://bbs.giga.net.tw/bencoder.php
BENCODER v1.1 - Encode your PHP script using bcompiler
Usage: bencoder [-f] -o FILE file1.php
bencoder [-f] -o OUTDIR file1.php file2.php ...
bencoder [-f] -o OUTDIR -a SRCDIR [-s SUFFIX] [-c] [-r]
-f : force overwriting even if the target exists
-o FILE : the file name to write the encoded script
(default to '-encoded.php' suffix)
-o OUTDIR : the directory to write all encoded files
-a SRCDIR : encode all files in this source directory
-s SUFFIX : encode the files with the SUFFIX extension only (default: php)
-c : copy files those shouldn't be encoded (no by default)`
shannah at sfu dot ca
23-May-2006 03:44
`>the special constant __FILE__ cannot be handled correctly by bcompiler
> (it will always contain the name of the original file that was compiled).
I would think that this is the preferred behavior anyways since the compilation should be independent from the source code. I would want to be able to compile any part of my source code without having to worry if any constants will change as a result of it. Hence it is better for __FILE__ to contain the name of the original file that was compiled.`
arplynn at gmail dot com
28-Apr-2006 08:49
`PHP seems to choke on trying to compile PHP5 classes with the private, protected or public modifiers. Additionally, when including files with properly compiled classes on PHP5, it works fine but when php tries to exit it throws a segmentation fault.
It's just not a great idea to use bcompiler for anything other than functions on PHP5, at least for now.`
tda at example dot com
07-Feb-2006 05:50
`Creating a function after checking if a function exists using function_exists will result in a "Zero Sized Reply" error.
this does NOT work any longer:
if (!function_exists("file_get_contents")) {
function file_get_contents($filename, $use_include_path = 0)
{ ...define your own function here... }
}
Apache returns: "Zero Sized Reply" after compilation.`
alan at akbkhome dot com
27-Oct-2005 07:32
`Note:
the special constant __FILE__ cannot be handled correctly by bcompiler (it will always contain the name of the original file that was compiled). There is no known way around this, as it is converted to a string by the Zend engine.`
add a note
bcompiler_load_exe bcsub

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST