php - 使用 PHP 持续检查文件是否存在
问题描述
我正在做一个项目,该项目要求我每 5 秒检查一次 PHP 文件是否存在,如果该文件存在,则重定向到该文件。
如果它不存在,则脚本应改为每 5 秒检查一次。
我该怎么做呢?我知道 file_exists(),但我将如何让它连续检查,而不仅仅是一次?
解决方案
你可以尝试使用这个
<?php
$x = 0;
$count = 5;
do {
if(!file_exists($file)){
$x++;
echo 'file loading';
sleep(5);//Delays the program execution for 5seconds before code continues.
}
else {
header('Location: '.$file);
exit();
}
}
while($x < $count); // this kind of regulates how long the loop should last to avoid maximum execution timeout error
if($x == $count){
echo 'file does not exist';
}
?>
推荐阅读
- python - 仅当 df2 中的列中的值在 df1 中时,才将 2 个数据框附加在一起
- ruby-on-rails - RoR 推送被 Heroku 拒绝“无法检测到 rake 任务”
- linux - 添加地理路由协议
- r - 使用汇总会改变我的计算结果
- javascript - 如何解决输入数字格式的问题?
- c - 蒙蒂霍尔问题 C 蒙特卡罗模拟
- c# - 不能为实体类型指定过滤器表达式。过滤器只能应用于层次结构中的根实体类型
- android - 为 Google play 64 位和 32 位构建一个 Bundle 应用程序
- python - 使用 RDFLib 对 SPARQL 查询进行 Python 日志记录
- oracle - 带有 SSL java.sql.SQLRecoverableException 的 AWS Oracle:IO 错误:连接重置 AWS