背景:
在工作中,编写一个脚本管理类,默认情况下会while(true)一直运行,该类中有个检查维护模式的行为,如果开启了维护模式,脚本就停止。因为每次在循环体内的首行去检查,如果检查频率过高,也是很高的一个访问量,所以就针对php常用到的缓存,做了简单的基准测试。
代码示例:
<?php
// 测试数据
$identifier = uniqid('demo_', false);
// 文件缓存
$cacheFile = '/upload/test/' . $identifier;
!is_dir(dirname($cacheFile)) && mkdir(dirname($cacheFile), 0755, true);
file_put_contents($cacheFile, microtime(true));
function fileCacheExists($identifier)
{
return file_exists