1.linux 安裝php
wget http://pecl.php.net/get/zendopcache-7.0.5.tgz
tar xzf zendopcache-7.0.5.tgz
cd zendopcache-7.0.5
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
Note:
If you want to use OPcache with » Xdebug, you must load OPcache before Xdebug.
若是你使用了Xdebug,您的配置中OPcache 要放到Xdebug前面。linux
在php.ini中加入:web
zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20100525/opcache.so
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緩存
其中:max_accelerated_files 設置的是緩存的文件,這個您須要到您的應用下面查看一下php文件的數量,能夠經過下面的命令統計:ide
find ./ ( -name '.php' -or -name '*.inc' ) -type f -print |wc -l
若是文件多,能夠設置的高一些。函數
整理了一下其在php.ini中各參數的使用說明,供你們參考,有一些不太懂的,就留空了,還請高手賜教。性能
名字 默認 可修改範圍 含義
opcache.enable 「1」 PHP_INI_ALL 是否啓用opcache
opcache.enable_cli 「0」 PHP_INI_SYSTEM 是否在CLI(即命令行時)啓用opcache
opcache.memory_consumption 「64」 PHP_INI_SYSTEM 爲opcache分配多少共享內存,單位M
opcache.interned_strings_buffer 「4」 PHP_INI_SYSTEM interned string的內存大小
opcache.max_accelerated_files 「2000」 PHP_INI_SYSTEM 最大緩存的文件數目。
實際上這個值會使用第一個大於你配置的數字的下列素數優化
{ 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987 },.net
如你將該值指定爲400,則實際上該值爲463.命令行
opcache.max_wasted_percentage 「5」 PHP_INI_SYSTEM
opcache.use_cwd 「1」 PHP_INI_SYSTEM 若是置爲1,則將當前路徑加入到文件key中,
以免可能產生的同文件名的文件key衝突
opcache.validate_timestamps 「1」 PHP_INI_ALL 若是置爲1,則OPCACHE會自動檢測文件的時間戳
(檢測週期爲revalidate_freq),
並根據文件的時間戳來更新opcode,若是置爲0,
則只能手動去重啓opcache或
重啓webserver以使更新後的php文件生效
opcache.revalidate_freq 「2」 PHP_INI_ALL opcache自動檢測文件是否更新的週期,單位秒。
若是是0,則每次請求時opcache都要進行檢測。
當validate_timestamps爲0時,本指令無效。
opcache.revalidate_path 「0」 PHP_INI_ALL
opcache.save_comments 「1」 PHP_INI_SYSTEM 是否保存文件中的註釋
opcache.load_comments 「1」 PHP_INI_ALL 是否load comments,與save_comments聯合起來使用,
若是該值爲0,則即便save_comments爲1,
那麼php腳本中的comments也是不使用的
opcache.fast_shutdown 「0」 PHP_INI_SYSTEM 是否打開快速關閉,
打開時可以使php在request shutdown時回收內存快
opcache.enable_file_override 「0」 PHP_INI_SYSTEM 若是置爲1,則每次調用file_exist() is_file() is_readable()函數時,
opcache將要檢查該文件是否被cache了,
這樣增長了檢查存在性和可讀性的開銷,
但避免了當validate_timestamps爲disable時返回錯誤文件狀態的風險。
opcache.optimization_level 「0xffffffff」 PHP_INI_SYSTEM 運行時控制優化的掩碼(幹什麼的?)
opcache.inherited_hack 「1」 PHP_INI_SYSTEM 5.3之前使用。5.3後廢棄
opcache.dups_fix 「0」 PHP_INI_ALL 爲解決「cannot redecllare class」 時,可將其置爲1
opcache.blacklist_filename 「」 PHP_INI_SYSTEM 設置黑名單文件,符合黑名單文件中定義的php文件將不被opcache。黑名單文件的例子以下:
; Matches a specific file.
/var/www/broken.php
; A prefix that matches all files starting with x.
/var/www/x
; A wildcard match.
/var/www/*-broken.php
一行爲一條規則,支持通配符,註釋以分號開頭
opcache.max_file_size 「0」 PHP_INI_SYSTEM 被cache的文件的最大size,單位bytes。0表示不限
opcache.consistency_checks 「0」 PHP_INI_ALL 若是置爲N,N非零,則opcache會每N個請求覈實一下cache的檢驗和。
這會損害性能,應該只在debug時使用
opcache.force_restart_timeout 「180」 PHP_INI_SYSTEM 若是opcache處於非active狀態,當N秒後opcache將自動重啓
opcache.error_log 「」 PHP_INI_SYSTEM opcache自身的errorlog文件路徑,爲空時則使用stderr
opcache.log_verbosity_level 「1」 PHP_INI_SYSTEM 日誌記錄level,默認只有fatal error和error
opcache.preferred_memory_model 「」 PHP_INI_SYSTEM opcache首選使用的內存模型,爲空時會選擇最適當的模型。
經常使用的有,mmap shm posix 和win32
opcache.protect_memory 「0」 PHP_INI_SYSTEM 運行php腳本時保護共享內存防止意外的寫入。
只對debug時有用。
opcache.mmap_base NULL PHP_INI_SYSTEM