PHP 5.2 時代,Zend Optimizer 是運行 Zend Guard 加密腳本的標準組件。但 PHP 5.3 發布後,Zend 官方停止更新 Optimizer,改推出 Zend Guard Loader。兩者不相容:用 Zend Guard 5.3+ 加密的腳本無法在 5.2 運行,反之亦然。
| PHP 版本 | 加密工具 | 運行組件 | 檔案名稱 |
|---|---|---|---|
| 5.2.x | Zend Guard 5.x | Zend Optimizer | ZendOptimizer.so / ZendOptimizer.dll |
| 5.3.x - 5.6.x | Zend Guard 6.x/7.x | Zend Guard Loader | ZendGuardLoader.so / ZendLoader.dll |
| 7.0+ | Zend Guard 12+ | Zend Loader (內建) | 無需獨立組件 |
ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gzZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gzZendGuardLoader-php-5.3-Windows.zip解壓後取得核心檔案:ZendGuardLoader.so (Linux) 或 ZendLoader.dll (Windows)。
# 建議放置於 PHP 擴展目錄
mkdir -p /usr/local/php/ext
cp ZendGuardLoader.so /usr/local/php/ext/
; 絕對路徑載入擴展
zend_extension = /usr/local/php/ext/ZendGuardLoader.so
; 啟用載入編碼腳本(預設開啟)
zend_loader.enable = 1
; 禁用授權檢查(提升效能,預設 0)
zend_loader.disable_licensing = 0
; 混淆支援等級(0-3,預設 3)
zend_loader.obfuscation_level_support = 3
; 授權檔路徑(如有)
zend_loader.license_path =
檢查方式:php -i | findstr "Thread Safety" → 必須顯示 disabled。
; 非線程安全版專用
zend_extension = C:\php\ext\ZendLoader.dll
zend_loader.enable = 1
zend_loader.disable_licensing = 0
zend_loader.obfuscation_level_support = 3
zend_loader.license_path =
若同時使用其他 Zend 組件,載入順序決定成敗:
; 1. 最先載入 IonCube Loader(如使用)
zend_extension = /path/to/ioncube_loader_lin_5.3.so
; 2. 再載入 Zend Guard Loader
zend_extension = /usr/local/php/ext/ZendGuardLoader.so
; 3. 最後載入 Zend Debugger(如使用)
zend_extension = /path/to/ZendDebugger.so
錯誤順序會導致:段錯誤、擴展無法載入、加密腳本執行失敗。
php -v
# 輸出應包含:
# Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies
# 或
# with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies
或建立 phpinfo.php 搜尋 "Zend Guard Loader" 區塊。
| 現象 | 可能原因 | 解決方案 |
|---|---|---|
| PHP 啟動報錯 "Failed loading ZendGuardLoader.so" | 路徑錯誤/架構不匹配/PHP 版本不符 | 確認絕對路徑、x64/x86 對應、PHP 5.3.x 專用版 |
| 加密腳本提示 "This script was encoded by Zend Guard..." 但不執行 | Loader 未生效或版本不符 | 檢查 phpinfo 中 Zend Guard Loader 區塊,確認 enable=1 |
| Windows 下 Apache 啟動失敗 | 使用了 TS 版 PHP 載入 NTS 專用 Loader | 更換 NTS 版 PHP 或使用對應 TS 版 Loader(官方未提供) |
| 與 Xdebug 衝突 | 兩者皆為 zend_extension | 調整載入順序:Zend Guard Loader 在 Xdebug 之前 |
Zend Guard 系列產品已逐漸淡出主流,建議新專案考慮:
php-obfuscator,輕量級保護本文詳細記錄了 PHP 5.3+ 環境下安裝 Zend Guard Loader 的完整流程,重點闡述了:版本對應關係、Windows NTS 限制、多擴展載入順序、驗證方法與常見錯誤排查。對於必須維護歷史加密專案的開發者,這是不可或缺的參考資料。