我通过 CLI 清除缓存的解决方法是创建一个这样的 bash 脚本
#!/bin/bash
WEBDIR=/var/www/html/
RANDOM_NAME=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)
echo "<?php opcache_reset(); ?>" > ${WEBDIR}${RANDOM_NAME}.php
curl https://127.0.0.1/${RANDOM_NAME}.php
rm ${WEBDIR}${RANDOM_NAME}.php
将其放在 /usr/local/bin/opcache-clear 中并使其可执行。
当我想清除缓存时,我只需在终端中运行“opcache-clear”。