OPcache 文件缓存刷新
PHP加载opcache扩展后,经常有文件由于OPcache缓存修改后不生效,写个脚本手动执行
<html>
<meta charset="utf-8"/>
<body>
<form action="" method="post">
<textarea name="files" rows=10 cols=60><?php echo $_POST["files"];?></textarea>
<p/>
每个文件一行,并用分号( ; )分割,例如:<br>
AppLibActiona.php;<br>
AppLibAction.php;<br>
<p/>
<input type="radio" name="app" value="crm" <?php if($_POST["app"]=="crm"){echo "checked="checked"";}?>/> CRM
<input type="radio" name="app" value="mobile" <?php if($_POST["app"]=="mobile"){echo "checked="checked"";}?> /> Mobile
<input type="submit" value="确定刷新"/>
</form>
</body>
</html>
<?php
if(isset($_POST) && trim($_POST["files"])){
$file_arrs=explode(";",trim($_POST["files"],";")); //获取要刷新的文件数组
$app=trim($_POST["app"]);
$root_path="/mnt/data/www/{$app}/"; //项目路径
//print_r($file_arrs);die;
foreach($file_arrs as $file){
if(trim($file)!=""){
$file=str_replace("\","/",trim(trim($file),"/")); //替换Linux路径符号
$file_path=$root_path.$file; //完整文件路径
$result=opcache_invalidate($file_path); //刷新文件
if($result){
echo $file_path,"文件刷新成功<br>";
}else{
echo $file_path,"文件刷新失败,可能文件不存在<br>";
}
}
}
}
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
