Skip to content

通过知识获得解放,通过技术获得自由

Menu
  • 专题目录
  • 液压相关
    • 液压技术
    • 液压相邻技术
    • 液压应用
  • 计算机相关
    • 计算机和软件
    • 网络和网站技术
  • 哲学
  • 关于本站
Menu

安装php的apcu扩展[0]

Posted on 2023年11月14日 by

本文适合php7.1.4但是不适合php7.4

  • 简介

APCU就一个功能:用户数据缓存(User Data Cache or Object Caching)。

这个APCU缓存和memcahce/redis不一样的地方。通过redis存储一个数据,在缓存有效期内,同一机器上的不同的PHP进程(FPM+CLI)都是能够取到这份数据的。

对于APCU而言,PHP-FPM模式下所有的php-fpm进程(即使是不同的pool)属于同一个父进程,所以是可以共享缓存数据的;但是cli模式每次都是单独一个全新进程,因而和php-fpm模式的进程是不能共享缓存数据的。

php官方解释APCu是剥离了操作码缓存的APC。从APCu 5.0.0开始提供PHP 7支持。它一方面是对于本身代码级别的缓存,另一方面是提供类似于redis的set、get这样的接口。

一般现在的架构模式下,负载均衡机器、服务集群、redis集群、mysql集群式相互独立运维的,服务间使用网络协议调用。apcu是基于共享内存技术建设的,多个cgi之间访问apcu中的cache可以完全等同于访问自己进程的一块内存一样,不需要发任何的网络请求。而不管是redis、mysql或者其他的独立服务的cache都需要发网络请求。

按照计算机存储器层次结构的理论,访问内存的速度大概在纳秒级别 ,网络请求的速度在毫秒级别,就单拿redis与之对比,10万次的数据读取,APCu大概是其速率的500多倍。

不过APCU在实际的使用中还是存在一定的局限性:

1)以扩展的方式接入,跟php这门语言有很强的耦合,而redis作为独立服务存在,使用协议接入
2)apcu受限于单机内存的限制,扩展受阻,而目前的redis集群模式已经可以做到动态扩容,理论上无容量风险
3)apcu数据存于单机内存,多机器之间的数据无法共享,这是他使用场景有限的最大阻碍
4)使用场景中一般用apcu来缓存数据量小、但是读取量大或者瞬间读取量大的场景。
  • 部署记录

1)安装apcu

cd /lnmp
wget https://www.fanlog.org/wp-content/uploads/2021/06/apcu.zip
unzip apcu.zip
tar zxvf apcu-5.1.16.tgz
cd apcu-5.1.16
/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config
make 
make install

2)使用apcu

修改php.ini

nano /usr/local/php/lib/php.ini
添加如下:
extension = apcu.so
apc.enabled= on
apc.shm_size= 64M
apc.enable_cli = on

重启php-fpm

systemctl restart php-fpm

打开wd1.soda101.xyz/phpinfo.php,显示如下:

  • 小结

apcu安装较为简单。

参考资料

  1. https://www.yangshujing.com/204.html
  2. https://taobig.org/?p=612
  3. http://urlink365.com/2020/07/21/APCU%E7%94%A8%E6%88%B7%E7%BC%93%E5%AD%98-PHP%E7%9A%84%E6%A0%87%E5%87%86%E6%89%A9%E5%B1%95/index.html

欢迎回来

希望本站对你有所帮助!

如有疑问请联系info@fanlog.org
2023 年 11 月
一二三四五六日
 12345
6789101112
13141516171819
20212223242526
27282930 
« 6 月    

AI辅助 (17)

© 2025 | Powered by Superbs Personal Blog theme
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT