php 缓存之 APC 和apcu
php opcode 缓存 apc.
其实,我自己的理解, php apc 缓存其实分两部分,
一部分是 缓存 类似于 java 编译的中间的 字节码, 不同于c 语言编译之后的二进制的机器码。 php apc 来缓存php解释器解析
php产生的 opcode, 哈哈。纯属个人的瞎理解,如有错误,请大家指出, 不甚感激。
还有一部分是 data cache, (key / value map ), 也就是数据缓存, 这点类似于 memerched 和 redis 缓存, 用来存储数据, 将数据库或者文件中的数据暂时缓存起来。以
提高访问速度。
APC的介绍
The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. Its goal is to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.
但是据我查的资料, apc 由于严重的bug ,php官方已经废弃了。 出现了一个 apcu , apcu的接口和apc 是一样的。
这里是一篇介绍的文章,非常不错 https://www.devside.net/wamp-server/installing-apc-for-php-5-5
这篇文章也是相当的好,大家有时间可以看看:https://support.cloud.engineyard.com/hc/en-us/articles/205411888-PHP-Performance-I-Everything-You-Need-to-Know-About-OpCode-Caches
下面是我自己写的测试代码: 注意, 用了一段时间后可能要清除一下缓存,否则会有效率问题, 方法:apc_clear_cache();
1 2 3 4 | <?php apc_store( 'name' , 'ysr' ); $name = apc_fetch( 'name' ); var_dump( $name ); |
浏览器访问该页面,是没问题的,输出为:
Installing APC for PHP 5.5 and 5.6
If you need to install and enable the php_apc extension for PHP 5.5 or 5.6, there is a way to accomplish this. But before you do this, there are a few things you have to be aware of:
- The last PHP version that had the php_apc extension included in was PHP 5.3. * Newer versions of PHP have replaced APC with php_opcache.
- The last APC release was php_apc 3.1.14, and while it worked with PHP 5.5, it was immediately removed due to some serious memory issues that could not be fixed. * php_apc 3.1.14 is not available anywhere, it was removed from all official sources.
- The only available release of APC is 3.1.13, and while it’s for both PHP 5.3 and 5.4, it’s only non-beta for 5.3 (i.e., not recommended for PHP 5.4).* php_apc 3.1.13 will not work with PHP 5.5+.
Having said that, APC has two parts to it…
- The opcode cache part that compiles and caches script code.
- And the data cache part that stores key/value pairs (e.g., just like memcached).
If your scripts require APC, more than likely they only do so because they use APC’s data cache part. And if you want to run those scripts under PHP 5.5 or 5.6, the APCu extension fully replaces APC, and is fully compatible with APC’s API.
APCu is the APC extension with the opcode cache part removed (which was the source of all APC issues) and the data cache part cleaned up. APCu has the same exact functions and configuration directives as APC – so it can be used as a drop-in replacement.
Also, from what I’ve gathered, APCu performs even better than memcache/memcached on single server setups (which is the case 95% of the time if you are using a WAMP such as WampDeveloper Pro).
Installing APCu For PHP 5.5
1. Download the latest build of APCu from –
http://windows.php.net/downloads/pecl/releases/apcu/
我下载的是
php_apcu-4.0.8-5.4-nts-vc9-x86.zip
For PHP 5.5 Standard:
php_apcu-4.0.7-5.5-ts-vc11-x86.zip
For PHP 5.5 FCGI:
php_apcu-4.0.7-5.5-nts-vc11-x86.zip
2. Extract out files php_apcu.dll and php_apcu.pdb into the proper PHP version package –
For PHP 5.5 Standard:
C:\WampDeveloper\Versions\Php\php-5.5.24.0-r1-win32-vc11-standard\ext\
For PHP 5.5 FCGI:
C:\WampDeveloper\Versions\Php\php-5.5.24.0-r1-win32-vc11-standard-fcgi\ext\
3. Edit php.ini, near end add section:
[APCu]
extension=php_apcu.dll
apc.enabled=1
apc.shm_size=32M
apc.ttl=7200
apc.enable_cli=1
apc.serializer=php
3. Save file. Restart Apache.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现