PHPWales 2020 - June 3rd to June 4th

Функции bcompiler

Контактная информация

Если у вас замечания, багфиксы, предложения по улучшению или вы просто хотите помочь развивать bcompiler, просто напишите письмо по адресу » Любая помощь приветствуется.


  • bcompiler_load_exe — Прочитать и создать классы из скомпилированного bcompiler исполняемого файла
  • bcompiler_load — Прочитать и создать классы из сжатого bz файла
  • bcompiler_parse_class — Читает байткод класса и передает его в заданную callback-функцию
  • bcompiler_read — Прочитать и создать классы из файлового дескриптора
  • bcompiler_write_class — Записывает байткод класса в файл
  • bcompiler_write_constant — Записывает заданную константу в виде байткода в файл
  • bcompiler_write_exe_footer — Записывает позицию начала байткода и терминирующий символ в конец файла
  • bcompiler_write_file — Сохраняет скрипт php в виде байткода
  • bcompiler_write_footer — Записывает символ \x00, обозначающий конец скомпилированных данных
  • bcompiler_write_function — Сохраняет заданную функцию в виде байткода
  • bcompiler_write_functions_from_file — Сохраняет все функции, определенные в скрипте, в виде байткода
  • bcompiler_write_header — Записать заголовок файла bcompiler
  • bcompiler_write_included_filename — Сохраняет подключенный файл в виде байткода
add a note add a note

User Contributed Notes 8 notes

mail - at- albertkok - dot - com
10 years ago
It's been a while since my past post, but yes, I'm still using bcompiler. I just found another problem that I think you should be aware of. It took me hours to find.

It pretty much comes to this: When compiling on a 64-bit Linux operating system, your compiled code will NOT run on a 32-bit version, and visa versa. It will merely echo the file's content.

Albert Kok
7 years ago
I'm using bencoder v1.6 and latest bcompiler ( -- 1.0.2 at time of writing this -- and I ran a test on PHP5 static class functions and regular class functions, and then ran a test with __FILE__. I encountered no problems. So, at least the static class issue and the __FILE__ issue is resolved now.

However, please continue your testing and reporting bugs (
Albert Kok
12 years ago
A few notes to succesfully configure PHP5 to load bcompiler.

In case of using Debian/Ubuntu Linux: When installing from the PECL (PEAR) package, make sure you have the php5-dev library installed in your system (apt-get install php5-dev).

Newer versions of Ubuntu may error out while installing bcompiler thru PECL, asking you to reinstall bzip2. This will not fix the installation. Instead, install the libbz2-dev library (apt-get install libbz2-dev) and try installing bcompiler from PECL again.

After installing bcompiler from PECL, don't forget to make sure you load the library in your PHP configuration for the new bcompiler functions to become available. This is done by adding the following line to the bottom of your php.ini file(s):

If you were to use the bcompiler functions thru your webserver, you need to restart it to reload the php configuration.

Albert Kok
roberto at spadim dot net dot br
12 years ago
hello guys, since bencoder don't work for __FILE__ constants i have a bcompiler script working, anyone that want it can send me an email
the source is 100% compatible with original file, the only problem is php5 new function methods that
if (!function_exists('function_name')){
function function_name()
don't work but it's a php5 new method for understand bytecode
arplynn at gmail dot com
13 years ago
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.
cdsheen+bencoder at gmail dot com
13 years ago
Here's a script to act as a front-end for bcompiler, which may be very similar to the eA ones:

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)
tda at example dot com
13 years ago
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")) {
file_get_contents($filename, $use_include_path = 0)
/*...define your own function here...*/ }

Apache returns: "Zero Sized Reply" after compilation.
codeslinger+uph80111 at compsalot dot com
11 years ago
try this, I believe that it will solve the problem with __FILE__


eval("\$Foo = dirname(__FILE__);");
"\n<br>FILE = '$Foo'\n";

To Top