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.
Regards,
Albert Kok
VIII. Compilador Bytecode de PHP
Introducción
| Aviso |
Esta extensión es EXPERIMENTAL. Esto significa que el comportamiento de esta extensión, los nombre de sus funciones y en definitiva TODO lo documentado sobre esta extensión, puede cambiar en una futura versión de PHP SIN AVISO. La advertencia queda hecha, y utilizar esta extensión queda bajo su propia responsabilidad. |
Bcompiler fue escrito por varias razones:
| Para codificar un script entero en una aplicación propietaria escrita en PHP. |
| Para codificar algunas clases y/o funciones en una aplicación propietaria escrita en PHP. |
| Para permitir la producción de aplicaciones PHP-GTK que puedan ser usadas del lado del cliente, sin necesidad de un php.exe. |
| Para hacer viable el estudio de un convertidor PHP al lenguaje de programación C. |
La segunda de estas metas se pueden alcanzar usando las funciones bcompiler_write_header(), bcompiler_write_class(), bcompiler_write_footer(), bcompiler_read(), y bcompiler_load(). Los archivos bytecode pueden estar escritos tanto descomprimidos, como en texto plano. La función bcompiler_load() lee un archivo bytecode comprimido con bzip, el cual suele ser 1/3 del tamaño original del archivo.
Para crear archivos del tipo exe, bcompiler tiene que ser usado con un archivo sapi modificado o una versión de PHP que haya sido compilada como una librería compartida. En este escenario, bcompiler lee el bytecode comprimido desde el final del archivo exe.
bcompiler puede mejorar su desempeño cerca del 30% cuando sólo se usa con bytecodes descomprimidos. Pero tenga presente que un bytecode descomprimido puede ser hasta 5 veces más grande que el código fuente original. Usando la compresión bytecode puede ahorrarle espacio, pero la descompresión requiere mucho más tiempo que analizar un código. Además, bcompiler no lleva a cabo alguna optimización bytecode; esto pudiera ser agregado en el futuro...
En cuanto a la protección del código, es seguro decir que sería imposible recrear el código fuente exacto desde el cual se construyó, y sin la compañía de comentarios en el código fuente. Efectivamente sería inútil usar los bytecodes de bcompiler para recrear y modificar una clase. Sin embargo, es posible recuperar información desde un archivo bytecode de bcompiler - así que no coloque sus contraseñas o cualquier otra cosa privada en él.
Instalación
Nota de instalación corta:
Necesitará tener al menos PHP 4.3 para que la compresión funcione.
Para instalar en PHP 4.3 o mayor, escriba en el intérprete de comandos de UNIX pear install bcompiler.
Para instalar en Windows, hasta que esté listo el mecanismo para el paquete de distribución binario, por favor busque los paquetes pre-construidos en la lista de correo pear-general. (o envíeles un correo electrónico si no pudo hallar una referencia).
Para instalar en versiones anteriores, necesita hacer algunos cambios ligeros al paquete.
extraer el archivo bcompiler.tgz en el directorio php4/ext. (Obténgalo directamente desde PECL http://pecl.php.net/get/bcompiler).
Si el nombre del nuevo directorio no es similar a bcompiler-0.x, debería cambiarle el nombre a bcompiler (a menos que sólo desee construirlo como un módulo PHP contenido desde de sí mismo).
Si está usando versiones anteriores a PHP 4.3, entonces necesitará copiar el archivo Makefile.in.old a Makefile.in, y config.m4.old a config.m4.
ejecute phpize en ext/bcompiler.
ejecute ./buildconf en php4 .
ejecute configure con --enable-bcompiler (y otras opciones que use).
make; make install
eso es todo.
Información de contacto
Si tiene comentarios, soluciones a fallos, mejoras o quiere ayudar a desarrollar esta bestia, puede enviarme un correo-e a alan_k@php.net. Cualquier ayuda es bienvenida.
- Tabla de contenidos
- bcompiler_load_exe -- Lee y crea clases desde un archivo exe de bcompiler
- bcompiler_load -- Lee y crea clases desde un archivo comprimido bz
- bcompiler_parse_class -- Lee los bytecodes de una clase y genera una llamada a una función definida por el usuario
- bcompiler_read -- Lee y crea clases desde un gestor de archivo
- bcompiler_write_class -- Escribe una clase determinada como bytecodes
- bcompiler_write_constant -- Lee una constante definida como bytecodes
- bcompiler_write_exe_footer -- Writes the start pos, and sig to the end of a exe type file
- bcompiler_write_file -- Writes a php source file as bytecodes
- bcompiler_write_footer -- Writes the single character \x00 to indicate End of compiled data
- bcompiler_write_function -- Writes an defined function as bytecodes
- bcompiler_write_functions_from_file -- Writes all functions defined in a file as bytecodes
- bcompiler_write_header -- Writes the bcompiler header
try this, I believe that it will solve the problem with __FILE__
<?php
eval("\$Foo = dirname(__FILE__);");
echo "\n<br>FILE = '$Foo'\n";
?>
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 bcompiler.so 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):
extension=bcompiler.so
If you were to use the bcompiler functions thru your webserver, you need to restart it to reload the php configuration.
Regards,
Albert Kok
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
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)
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.
Creating a function after checking if a function exists using function_exists will result in a "Zero Sized Reply" error.
<?php
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.
