Answer the question
In order to leave comments, you need to log in
How to cache json using php?
Tell me how to cache a JSON file, the file is connected from another site, and must first go to the tmp folder and then be processed from it.
$file = 'Внешний сайт/json/liveu.json';
$cache_path = "tmp"; // папка с кэш-файлами на сервере
$cache_file = sprintf($file, $cache_path);
$cache_ttl = 900; // время жизни кэша в секундах
$html = ''; // HTML код для вставки на страницу
if( file_exists( $cache_file) && (time() - filemtime($cache_file)) < $cache_ttl) {
// берём кэшированные данные
$html = file_get_contents( $cache_file);
} else {
$html = 2;
}
echo $html;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question