原文:PHP函數參考01-opcache - 9ong
PHP函數參考02-錯誤處理與日志記錄 - 9ong
opcache
OPcache 通過將 PHP 腳本預編譯的字節碼存儲到共享內存中來提升 PHP 的性能,存儲預編譯字節碼的好處就是省去了每次加載和解析 PHP 腳本的開銷。
PHP 5.5.0 及后續版本中已經綁定了 OPcache 擴展,可通過phpinfo查看zend OPcache信息。
-
opcache的用處
沒有使用opcache的腳本輸出:
php script => parse => compile => execute => output
使用opcache的腳本再次輸出:
php script => opcache => execute => output
-
opcache php.ini配置:
使用下列推薦設置來獲得較好的性能:
```ini
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
```
-
opcache常用函數:
-
opcache_compile_file — 無需運行,即可編譯并緩存 PHP 腳本。
opcache_compile_file( string $file) : boolean
-
opcache_is_script_cached — Tells whether a script is cached in OPCache。
opcache_is_script_cached( string $file) : bool
-
opcache_reset — 重置字節碼緩存的內容
opcache_reset() : boolean
-
APCu擴展
APC 插件曾經包含字節碼和對象緩存功能,但是自從 Zend 官方推出了 Opcache 后,APC 開發者就將字節碼緩存功能刪掉了,后來推出了 APCu 只保留對象緩存。APCu是APC的升級版。
也就是現在的APCu擴展像是memcache和redis一樣的對象緩存功能。
Yac擴展
Yac 是為PHP實現的一個基于共享內存, 無鎖的內容Cache。
Yac (Yet Another cache)是鳥哥惠新宸的作品之一。
could be used to replace APC, local memcache.
經常用來代替APC,本地緩存。