Good evening. I have personal accounts on my site. When authorizing a user, the system looks at whether it has a cache in the personal account, if not, it loads from the database and loads it into the cache. The cache is built on files of the form USER_ID.txt so all changes that the user makes are saved to the cache. Then cron every 10 minutes, checks if there are user cache files, if there is, then enumerates and saves data to the database, then clears the cache. Everything seems to be normal, but sometimes there is such a problem that the information was not updated in the database, but the cache file was deleted, thereby rolling back. Here is the script:
function Save($folder) { global $Mysql; $GetFilesDir = Local_temp::GetFilesDir($folder); if($GetFilesDir == false){ $Return['error']['get_files_dir'] = true; return $Return; } foreach($GetFilesDir as $key=>$file_name) { $Save = array(); $Get = Local_temp::Get($folder.$file_name); if($Get == false) continue; $result = $Mysql->query("SELECT * FROM `users` WHERE `id`='{$Get['id']}' "); $myrow = $Mysql->get_array($result); if($myrow == false) continue; foreach($myrow as $k=>$v) { if(is_numeric($k)) continue; if($Get[$k] != $v) $Save += array($k=>$Get[$k]); } if($Save == false) continue; $UpdateUser = Update_user::Update($Save, $Get['id'], false); if(mysql_affected_rows() != 1) continue; $history_file_name = date('Y').'_'.date('m').'_'.date('d').'_'.date('H').'-'.date('i').'.txt'; Local_temp::NewFolder('local_history_temp/users/'.$Get['id']); Local_temp::Set('local_history_temp/users/'.$Get['id'].'/'.$history_file_name, $Get); Local_temp::Drop($folder.$file_name); } return true; } /* Local_temp::Get($folder.$file_name); - Получение файла кеша $UpdateUser = Update_user::Update($Save, $Get['id'], false); - Обновление БД local_history_temp - Директория отвечающая за архив кеша (так я и увидел, что систему откатывает) Local_temp::Set('local_history_temp/users/'.$Get['id'].'/'.$history_file_name, $Get); - Новый кеш Local_temp::Drop($folder.$file_name); - Удаление кеша */