php - PHP 函数包括 -> 网站未加载
问题描述
当我尝试调用包含在整个站点上方几行的函数时,无法重新加载。
$object = 'termin';
$cache_available = check_cache($object);
这就是我调用函数的方式,定义如下所示:
function check_cache($object){
$file = '../../cache/' . $object . '.json';
if(file_exists($file)){
$time_cache = date ("H:i:s", filemtime($file));
$time_now = date ("h:i:sa");
$diff = strtotime($time_now) - strtotime($time_cache);
if($diff <= 60) {return true; } //Neu genug
else {return false;} //Zu alt
}
return false;
}
有人可以告诉我是什么导致了错误。
未加载的解释:---当我导航到浏览器中的文件夹(localhost,xampp)并单击文件以打开它时会加载一小段时间,但随后会再次显示该目录。
解决方案
那 check_cache 看起来不正确。它有错误的路径检查开始和一个很长的返回语句。用 if 和 else。我重写了它,尝试一下,看看它是否有效。
function check_cache($object) {
$file = __DIR__ . '/../../cache/' . $object . '.json';
if(file_exists($file)){
$time_cache = date ("H:i:s", filemtime($file));
$time_now = date("H:i:s");
$diff = strtotime($time_now) - strtotime($time_cache);
return $diff <= 60;
}
return false;
}
推荐阅读
- angular - 角度嵌套反应形式 registeronchange 错误
- sql - SQL:选择语句,聚合函数列不带过滤器,另一列带过滤器
- javascript - 如何使用 Array.join() 加入 html 元素
- sql - 在 SSRS 中使用存储过程代替 SQL 查询时性能下降
- html - Django 模板继承不能正常工作
- kotlin - 从数组和对象中检索数据的任何功能性方法?
- weblogic12c - 将 OHS 11.1.1.9 连接到 FMW 12.2.1.4
- date - 获取产品在 Opencart 3 中的最后更新日期
- three.js - 使用非模块的 es6 类在 three.js 中合并指针锁定控制 API 很困难
- javascript - 如何翻转每个字符及其旁边的字符。Javascript