首页>>帮助中心>>香港服务器centos清除op缓存途径

香港服务器centos清除op缓存途径

2025/1/10 78次
香港服务器在 CentOS 系统中,清除 OPcache(Optimizing PHP Cache)可以通过以下几种方法:

命令行清除: 使用以下命令可以清除整个 OPcache:
echo > /var/run/opcache/opcache.stat
sudo systemctl restart httpd
复制代码
或者,如果你使用的是 PHP-FPM,重启 PHP-FPM 服务:
sudo systemctl restart php-fpm
复制代码
通过 PHP 脚本清除: 创建一个名为 clear_opcache.php 的文件,将以下内容粘贴到文件中:
<?php
if (function_exists('opcache_reset')) {
opcache_reset();
echo "OPcache has been reset.";
} else {
echo "OPcache is not enabled.";
}
?>
复制代码
然后,通过浏览器访问这个文件(例如:http://your_server_ip/clear_opcache.php),或者使用 curl 命令:
curl http://your_server_ip/clear_opcache.php
复制代码
修改 PHP 配置文件: 找到你的 PHP 配置文件(php.ini),找到或添加以下行:
zend_extension=opcache.so
opcache.enable=1
opcache.validate_timestamps=0
opcache.revalidate_freq=0
opcache.fast_shutdown=1
复制代码
其中,opcache.revalidate_freq 的值决定了 OPcache 何时重新验证 PHP 脚本。将其设置为 0 可以确保每次请求都重新验证脚本。 修改完配置文件后,重启 PHP-FPM 或 Apache 服务:
sudo systemctl restart php-fpm
复制代码
或者
sudo systemctl restart httpd
复制代码
请注意,频繁清除 OPcache 可能会影响性能,因此在需要清除缓存时谨慎操作。

购买使用一诺网络香港服务器,可以极大降低初创企业、中小企业以及个人开发者等用户群体的整体IT使用成本,无需亲自搭建基础设施、简化了运维和管理的日常工作量,使用户能够更专注于自身的业务发展和创新。香港服务器低至29元/月,购买链接:https://www.enuoidc.com/vps.html?typeid=2