星期一, 十月 13, 2008
安裝 PHP bcompile 做 編譯/加密 原始碼
PHP 的程式在公司在交付程式中, 比較麻煩的就是要如何把原始碼編譯或加密, 免費的方案, 可以考慮用 bcompiler(PHP bytecode Compiler).
不過這套於 PHP5 的物件寫法, 繼承等等, compiler 後執行會有問題, 純 function / include 等等, 是正常的.
PHP bcompiler 安裝步驟
下述環境於 Debian / Ubuntu Linux 安裝
- apt-get install libbz2-dev php-pear php5-dev # 因為 pecl compile bcompiler 需要 libbz2(bz2 library)
- pecl install channel://pecl.php.net/bcompiler-0.8 # 因為 bcompiler 是 beta, 不是 stable, 所以需要完整路徑.
- cat "extension=bcompiler.so" >> /etc/php5/conf.d/bcompile.ini
- /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();
?>
- 編譯: php bcompiler.php # 會發現有產生出 example.phb (或於 bcompiler.php 有另外取名字的 xxx.php)
- 執行: php example.phb # 會秀 hello, 然後此檔案已經是編譯過的 php code.
另外查到 使用 bcompiler 來編譯(加密)您的 PHP 原始碼 這篇的作者, 寫了一個 bencoder 的好用程式, 可以 compile 整個目錄, 詳細可見: BENCODER v1.3 - Encode your PHP script using bcompiler
Bencoder 安裝使用
- wget http://bencoder.urdada.net/bencoder
- chmod +x ./bencoder
- vim bencoder # 修改 php 執行路徑, Debian PHP 存放路徑在 /usr/bin/php
#!/usr/local/bin/php 改成 #!/usr/bin/php
- 執行: ./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
您好~
請問目前 bcompile 還是不能支援 物件寫法, 繼承寫法嗎? 有其他辦法可以解決嗎?
請不吝指教... 謝謝~
Comment by
calos
(04/23/2009 23:11)
編譯其他程式用的檔案 bcompiler.php
Comment by
Caesar
(04/27/2009 17:03)
發表迴響
PS: 若無法留言, 請先確認是否有打開 JavaScript, 造成您的困擾, 實在萬分對不起 Orz...(如果無法留言, 勞煩可以發信給我好嗎? 謝謝.)
PS2: 若您的留言被誤判, 我都會再自行看過, 不需要一直重覆張貼~
PS2: 若您的留言被誤判, 我都會再自行看過, 不需要一直重覆張貼~



