新版 PHP 預設啟用 APC 模組後造成 class 找不到的錯誤

假設環境:
PHP 5.3.20
Apache/2.2.23 (Unix)

aaa.php 檔案裡面有 AAA class,bbb.php 檔案裡面有 BBB class,bbb.php 中 include aaa.php。BBB class 的 b_func() 函式裡面用到 AAA class (即:$oA = new AAA())。

說明:
APC (Alternative PHP Cache) 是 PHP 的一個延伸模組套件,是 PHP 的另一種快取 (cache) 機制,可以直接拿既有的 OPCODE 執行、免去每次都直譯 php 程式產生 OPCODE 來跑,進而加快 php 程式的執行速度,號稱可以提昇 20% 到 30% 的速度。
筆者將手邊的 PHP 程式轉移到新版 PHP 環境下執行時,PHP 卻拋出「class 找不到」的錯誤訊息,類似以下 log 訊息:

[Tue Jan 29 04:04:46 2013] [error] [client 123.234.171.235] PHP Fatal error: Class ‘AAA’ not found in /sites/prj1/bbb.php on line 32

Continue reading “新版 PHP 預設啟用 APC 模組後造成 class 找不到的錯誤”