支持開源不代表反對保護商業邏輯。公司專案、授權機制、核心演算法若需部署至客戶伺服器,原始碼加密能提高逆向工程門檻。Zend Guard 商業授權昂貴且曾被破解,php_screw 是一套輕量、開源、可自訂加密種子的替代方案。
my_screw.h,修改陣列中的數字(SEED),長度與數值任意,作為加密金鑰。$ phpize
$ ./configure
$ make
若報 make: *** No targets specified and no makefile found. Stop.,通常是 autoconf 未裝,請先 yum install autoconf 或 apt-get install autoconf。modules/php_screw.so 複製至 PHP 擴充套件目錄(如 /usr/lib/php/extensions/...),在 php.ini 加入 extension=php_screw.so,重啟 PHP-FPM/Apache。$ cd tools
$ make
產出 screw 執行檔,放入 $PATH(如 /usr/local/bin)。$ screw a.php
Success Crypting(a.php)
原檔會備份為 a.php.screw,a.php 變為加密後內容,執行行為完全一致。現象:require 'encrypted.php'; 在 include_path 尋找時,PHP 未經過 screw 解密直接讀取亂碼。
解法:
require __DIR__ . '/encrypted.php';require './sub/encrypted.php';php_screw 以「編譯期自訂 SEED + 執行期擴充套件解密」機制,提供低門檻、高彈性的原始碼保護。適合中小型商業專案、授權檢查模組、模板引擎核心等場景。