• « bcompiler_write_constant
  • bcompiler_write_file »
  • PHP Manual
  • bcompiler 函数
  • 写入开始位置以及 exe 类型文件的结尾信号

bcompiler_write_exe_footer

(PECL bcompiler >= 0.4)

bcompiler_write_exe_footer — 写入开始位置以及 exe 类型文件的结尾信号

说明

bcompiler_write_exe_footer ( resource $filehandle , int $startpos ) : bool

一个 EXE(或可自执行)文件由 3 部分组成:

  • The stub (可执行代码,例如一个编译过的 c 程序) 加载了 PHP 解释器、bcompiler 扩展、储存的字节码并初始化调用指定函数(例如 main) 或类的方法(例如 main::main)。
  • 字节码(仅在那时未压缩)
  • bcompiler 的 EXE 尾部

为了得到适合的 stub 你可以编译位于 bcompiler CVS examples/embed 目录里 基于 php_embed 的 stub phpe.c。

参数

filehandle

fopen()返回的一个文件句柄。

startpos

字节码在文件中开始的位置,可以通过 ftell() 获取。

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE。

范例

Example #1 bcompiler_write_exe_footer() 例子

<?php

/* 创建输出的文件(example.exe) */
$fh = fopen("example.exe", "w");

/* 1) 写入一个 stub (phpe.exe) */
$size = filesize("phpe.exe");
$fr = fopen("phpe.exe", "r");
fwrite($fh, fread($fr, $size), $size);
$startpos = ftell($fh);

/* 2) 写入字节码 */
bcompiler_write_header($fh);
bcompiler_write_class($fh, "myclass");
bcompiler_write_function($fh, "main");
bcompiler_write_footer($fh);

/* 3) 写入 EXE 尾部 */
bcompiler_write_exe_footer($fh, $startpos);

/* 关闭输出的文件 */
fclose($fh);
?>

注释

Warning

此函数是实验性的。此函数的表象,包括名称及其相关文档都可能在未来的 PHP 发布版本中未通知就被修改。使用本函数风险自担 。

参见

  • bcompiler_write_header() - 写入 bcompiler 头
  • bcompiler_write_class() - 写入定义过的类的字节码
  • bcompiler_write_footer() - 写入单个字符 \x00 用于标识编译数据的结尾