我透過 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」。