(PECL bcompiler >= 0.4)
bcompiler_write_exe_footer — 寫入開始位置以及 exe 類型文件的結尾信號
說明
bool bcompiler_write_exe_footer ( resource$filehandle
, int $startpos
)
一個 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 用于標識編譯數據的結尾