我已经使用 PECL bcompiler 扩展很长时间了。一切都很好。但是,我发现将工作脚本移动到另一个 linux 系统(CentOS -> FreeBSD)会导致将 bcompiled 程序部分包含到基本脚本中出现问题(运行时屏幕上出现垃圾)。PHP(5.2.10)和bcompiler extension(最新)的版本是一样的。所有源代码都在两个 linux 系统中安装,没有错误。Bcompiler 使用 dl() 函数正确加载:没有错误,所有 bcompiler 的函数都在工作。
我试图将任务分为两部分:
CentOS:只编译没有页眉和页脚的内容:
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:在编译模块中添加页眉和页脚:
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; }
在 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...
垃圾消失了,但 PHP 提示:致命错误:无法在 [filename.php on line 40] 中继承。同时,两个系统上的页眉和页脚的完整编译给出了积极的结果。
问题出现了:Bcompiled 字节码对父系统是否唯一以及我如何解决这个问题。我的重要任务是将编译后的模块免费转移到安装了 PHP 和 Bcompiler 的各种 Linux 系统。