gpt4 book ai didi

PHP + MySQL : File reading limit and connection error

转载 作者:行者123 更新时间:2023-11-29 23:53:18 26 4
gpt4 key购买 nike

我在文件中查询缓存时遇到问题。我有一段代码试图获取带有序列化查询结果的文件,如果找不到文件,或者比某一天早,那么我将尝试连接到数据库并远程获取它。代码如下所示:

    // Getting cache file function
$cur_time = @time();
$time_modified = @filemtime($file_path);
if ($cur_time > ($time_modified + $cache_period_hours))
return NULL;
else
return unserialize(file_get_contents($file_path));

//If NULL is returned get result remotely;

if($result === NULL){
if (!db::connect("base", "192.168.1.111", "root", "password"))
die("Database error. Can not connect to database.");

//Execute query, write to file serialized result
}

当我的流量很大时,我会收到此错误:

Lost connection to MySQL server at 'reading authorization packet', system error: 0.

但我不知道为什么当我有新的缓存文件时脚本甚至尝试连接到数据库。有多少用户可以同时读取同一文件有限制吗?还有什么办法可以防止这个 MySQL 错误吗?

最佳答案

更改为:

if ($cur_time > ($time_modified + $cache_period_hours*3600))

这会将 $cache_period_hours 转换为秒,以匹配其他变量的单位。

关于PHP + MySQL : File reading limit and connection error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25494797/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com