开发插件写入文件缓存
一、函数
$script 文件名 
$cachedata 文件内容 
$prefix 文件前缀
function writetocache($script, $cachedata, $prefix = 'cache_') {
    global $_G;
    $dir = DISCUZ_ROOT.'./data/sysdata/';
    if(!is_dir($dir)) {
        dmkdir($dir, 0777);
    }
    if($fp = @fopen("$dir$prefix$script.php", 'wb')) {
        fwrite($fp, "");
        fclose($fp);
    } else {
        exit('Can not write to cache files, please check directory ./data/ and ./data/sysdata/ .');
    }
}二、用法
global $_G;
//引入文件
require_once 'source/function/function_cache.php';
@include_once 'data/sysdata/cache_dzl8_rurl.php';
//储存内容
$contents['username']="test";
$contents['uid']=123;
$dateline=TIMESTAMP;
//整理
$cacheArray = "$contents=".arrayeval($contents).";n";
$cacheArray .= "$dateline=$dateline;n";
//写入
writetocache('dzl8_rurl', $cacheArray);三、效果
在文件夹 datasysdata 中会多出一个 cache_dzl8_rurl.php 的文件,并且文件的内容为:
 'test',
  'uid' => 123,
);
$dateline=1519979117;
?> 
											
				