File size: 928B
<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/system/App.php');
if ($sys->isAjax())
{
/*
if (empty($me['cache_file'])) Base::update('user', $me['id'], ['cache_file' => $core->hash(20).'.dat']);
*/
$cacheFile = ROOT.'/system/cache/chat/check-messages.dat';
if (!file_exists($cacheFile)) file_put_contents($cacheFile, time(), LOCK_EX);
$lastAjaxCall = isset($_GET['timestap']) ? (int) $_GET['timestap'] : 0;
$lastChangeFile = filemtime($cacheFile);
while ($lastChangeFile <= $lastAjaxCall)
{
usleep(10000);
clearstatcache();
$lastChangeFile = filemtime($cacheFile);
}
$dataSourceFile = file_get_contents($cacheFile);
$json = [
'success' => 1,
'comment' => 'INFO: '.$dataSourceFile,
'timestap' => $lastChangeFile,
];
}
else
{
$json = [
'error' => 1,
'comment' => '404 Bad Request',
];
}
echo json_encode($json, JSON_UNESCAPED_UNICODE);