在我的IIS 7.5 web服务器上,我正在运行PHP 5.6与wincache扩展(1.3.6.1)一起缓存我的PHP脚本的操作码。这应该可以减少服务器上的CPU负载,因为PHP脚本不必在每次请求进来时都重新编译。
然而,我没有看到CPU负载明显下降。有了3个客户端,我的web服务几乎达到了极限(平均80%的cpu利用率),这和没有wincache一样多。
这是php.ini
[PHP_WINCACHE]
extension=php_wincache.dll
; Full reference: http://php.net/manual/en/wincache.configuration.php
wincache.fcenabled = 0
wincache.ocenabled = 1
wincache.ucenabled = 0
wincache.fcachesize = 64
wincache.fcndetect = 0
wincache.maxfilesize = 256
wincache.chkinterval = 10
wincache.enablecli = 0
我必须禁用文件缓存,因为:https://serverfault.com/questions/643458/failure-in-php-minit-functionwincache-with-wordpress-microsoft-azure-and-iis
print_r(wincache_ocache_fileinfo())
打印这个:
Array
(
[total_cache_uptime] => 303
[is_local_cache] => 1
[total_file_count] => 42
[total_hit_count] => 32160
[total_miss_count] => 42
[file_entries] => Array
... (skipped precise file info for brevity)
print_r(wincache_ocache_meminfo())
给了我这个:
Array
(
[memory_total] => 100663296
[memory_free] => 99769616
[num_used_blks] => 1677
[num_free_blks] => 1
[memory_overhead] => 26880
)
有什么建议,为什么我没有看到wincache有任何影响?我还可以尝试什么来减少我的web服务器上的CPU负载?
所以看起来好像PHP现在有一个内置的操作码缓存,Zend Opcache。激活/配置,而不是Wincache为我工作。我现在看到了操作码缓存的作用,尽管它没有我预期的那么大。
从PHP 5.5开始,可以通过向php.ini
添加以下行来激活Zend Opcache扩展:
zend_extension=php_opcache.dll
[opcache]
opcache.enable=1
关于如何配置/调整Zend Opcode扩展也请参阅此页:http://php.net/manual/en/book.opcache.php