I have been using PECL bcompiler extension for a long time. All is good. However, I have found that the moving the working script to another linux system (CentOS -> FreeBSD) causes a problem with include of the bcompiled program part to the basic script (trash appears on the screen on running). The versions of PHP (5.2.10) and bcompiler extension (the latest) are the same. All sources were installed without errors in both linux systems. Bcompiler is loaded correctly using dl() function: no errors, all bcompiler's functions are working.
I tried to devide the task into two parts:
CentOS: Compile only content without header and footer:
function bc($ext = "b") { global $SCRIPT_DIR, $INCLUDES; echo "Bcompiler is loaded. Compiling modules ... \n"; foreach($INCLUDES as $inc_file){ echo "$inc_file.php "; $php_file = "$SCRIPT_DIR/include/$inc_file.php"; if(!file_exists($php_file)){ echo "not found!\n"; continue; } else echo "=> $inc_file.$ext\n"; $fh = fopen("$SCRIPT_DIR/modules/b/$inc_file.$ext", "w"); bcompiler_write_file($fh, $php_file); fclose($fh); } return; }
FreeBSD: Addition of the header and footer to the compiled modules:
function b2bin() { global $SCRIPT_DIR, $INCLUDES; echo "Bcompiler is loaded. Processing modules ... \n"; foreach($INCLUDES as $inc_file){ echo "$inc_file.b "; $b_file = "$SCRIPT_DIR/modules/$inc_file.b"; // without header and footer if(!file_exists($b_file)){ echo "not found!\n"; continue; } else echo "=> $inc_file.bin\n"; $content = file_get_contents($b_file); $target_bin_file="$SCRIPT_DIR/modules/$inc_file.bin"; // with header and footer $fh = fopen($target_bin_file, "w"); bcompiler_write_header($fh); fwrite($fh,$content); bcompiler_write_footer($fh); fclose($fh); } return; }
Starting main program on FreeBSD [filename.php]:
if(!extension_loaded('bcompiler')) dl('bcompiler.so'); if(!function_exists("bcompiler_read")){ exit("error: PHP Bcompiler module not loaded. Install Bcompiler from https://pecl.php.net/package/bcompiler.\n"); } /*line 40*/ foreach( $INCLUDES as $inc_file) include_once ("$SCRIPT_DIR/modules/$inc_file.bin");
shedule_run(); ...and so on...
Trash disappears, but PHP informs: Fatal error: unable to inherit in [filename.php on line 40]. At the same time the full compilation with header and footer on both systems gives the positive result.
The question arises: Is the Bcompiled bytecode unique to the parent system and how I can get around the problem. My significant task is free transfer of the compiled modules to various Linux systems where PHP and Bcompiler were installed.