星期一, 十月 13, 2008

安裝 PHP bcompile 做 編譯/加密 原始碼

PHP 的程式在公司在交付程式中, 比較麻煩的就是要如何把原始碼編譯或加密, 免費的方案, 可以考慮用 bcompiler(PHP bytecode Compiler).

不過這套於 PHP5 的物件寫法, 繼承等等, compiler 後執行會有問題, 純 function / include 等等, 是正常的.

PHP bcompiler 安裝步驟

下述環境於 Debian / Ubuntu Linux 安裝

  1. apt-get install libbz2-dev php-pear php5-dev # 因為 pecl compile bcompiler 需要 libbz2(bz2 library)
  2. pecl install channel://pecl.php.net/bcompiler-0.8 # 因為 bcompiler 是 beta, 不是 stable, 所以需要完整路徑.
  3. cat "extension=bcompiler.so" >> /etc/php5/conf.d/bcompile.ini
  4. /etc/init.d/apache2 restart

確認 Module 是否載入

  • php -m | grep bcompiler
  • phpinfo(); # 看是否有載入 bcompiler module

PHP bcompiler 使用

先寫一個編譯程式, 準備把 example.php 編譯成 example.phb (或 xxx.php 都可以), 詳細可見: bcompiler_write_file.

編譯其他程式用的檔案 bcompiler.php
<?php
$fh = fopen("example.phb", "w");
bcompiler_write_header($fh);
bcompiler_write_file($fh, "example.php");
bcompiler_write_footer($fh);
fclose($fh);
?>
hello.php
<?php
function hello()
{
   echo "hello\n";
}
?>
example.php
<?php
include('hello.php');
hello();
?>
  1. 編譯: php bcompiler.php # 會發現有產生出 example.phb (或於 bcompiler.php 有另外取名字的 xxx.php)
  2. 執行: php example.phb # 會秀 hello, 然後此檔案已經是編譯過的 php code.

另外查到 使用 bcompiler 來編譯(加密)您的 PHP 原始碼 這篇的作者, 寫了一個 bencoder 的好用程式, 可以 compile 整個目錄, 詳細可見: BENCODER v1.3 - Encode your PHP script using bcompiler

Bencoder 安裝使用

  1. wget http://bencoder.urdada.net/bencoder
  2. chmod +x ./bencoder
  3. vim bencoder # 修改 php 執行路徑, Debian PHP 存放路徑在 /usr/bin/php
    #!/usr/local/bin/php 改成 #!/usr/bin/php
  4. 執行: ./bencoder -f -o php/Breadcrumb_ben/ -s php/Breadcrumb/ -r
    encoded: php/Breadcrumb_ben//first.php
    encoded: php/Breadcrumb_ben//index.php
    encoded: php/Breadcrumb_ben//bread.php
    encoded: php/Breadcrumb_ben//second.php
相關標籤

this is comment icon 您好~ [回覆]

請問目前 bcompile 還是不能支援 物件寫法, 繼承寫法嗎? 有其他辦法可以解決嗎?
請不吝指教... 謝謝~

Comment by calos (04/23/2009 23:11)

this is comment icon 回 calos [回覆]

沒有聽說耶, 我建議你去找一些需要付費的 compile, free 的好像還沒有看到可以支援物件的.

Comment by Tsung (04/24/2009 00:17)

this is comment icon 編譯其他程式用的檔案 bcompiler.php [回覆]

為什麼我用這個方法弄出來的檔案用記事本還是看到內容的??
Comment by Caesar (04/27/2009 17:03)

this is comment icon 回 Caesar [回覆]

阿? 跟原本檔案內容都一樣?

Comment by Tsung (04/28/2009 10:10)

this is comment icon [回覆]

try php_screw

Comment by Fwolf (06/15/2009 11:07)

this is comment icon 回 Fwolf [回覆]

感謝指點~ Orz..

Comment by Tsung (06/15/2009 11:50)
Add this page to del.icio.us

發表迴響

標題

內容 (限制 1000 字)

暱稱

電子郵件

個人網頁


 authimage


PS: 若無法留言, 請先確認是否有打開 JavaScript, 造成您的困擾, 實在萬分對不起 Orz...(如果無法留言, 勞煩可以發信給我好嗎? 謝謝.)
PS2: 若您的留言被誤判, 我都會再自行看過, 不需要一直重覆張貼~