caching - Faster way to write 20 remote files to a cache php -
I currently have this code, it brings the JSN data file for each hour and the whole day's file from an API. This then caches the results for faster spread. It currently takes ~ 10 to get all files and to use them (no caching), it takes ~ 1 to execute with the cache, but when the cache is stuck, Covers ~ with ~ 80 cache. Obviously there are other codes running on this but it is slow bit $ this- & gt; There are 24 elements in hour
.
What is a fast way to get files & amp; Get forecast weather data from the * .o * @Return array * Overall Public Data * / Public Function getData ($ kernelDir) {$ apiSite = 'https: / /api.forecast.io/forecast/'; $ Url = $ api site $ this- & gt; APKI '/' $ THIS- & gt; Latitude ',' $ this- & gt; Longitude; If (! File_exists ($ kernelDir. '/ Cache / api /'. $ This- & gt; Latitude. '$$ - this- & gt; Latitude)) {$ weatherFile = @file_get_contents ($ url); $ Fp = fopen ($ kernelDir. '/ Cache / api /'. $ This- & gt; latitude. '$. $ This- & gt; latitude,' w + '); Filitt ($ fp, $ weather file); Fclose ($ FP); } And {$ weatherFile = @file_get_contents ($ colonel.dir./cache/api/ '. $ This-> latitude.'. '$ This- & gt; longitude); } $ This- & gt; WeatherData ['day'] = @ json_decode ($ weather file, true); $ This- & gt; GetHours (); Forex Currency ($ this- & gt; hour $ normal => gt; $ unixTimestamp) {$ url = $ api site $ this- & gt; APKI '/' $ THIS- & gt; Latitude ',' $ this - & gt; Longitude ',' $ UnixTimestamp; If (! File_exists ($ kernelDir. '/ Cache / api /'. $ This- & gt; latitude. '$$ - this-> longitude'. '.' $ UnixTimestamp)) $ $ WeatherFile = @file_get_contents ( $ Url); $ Fp = fopen ($ kernelDir. '/ Cache / api /'. $ This- & gt; Latitude. '' $ This-> Longitude. '.' $ UnixTimestamp, 'w +'); Filitt ($ fp, $ weather file); Fclose ($ FP); } And {$ weatherFile = @file_get_contents ($ kernel.dir / .cache / api / '. $ This- & gt; latitude.', '. $ This-> longitude.', '. $ UnixTimestamp); } $ This- & gt; WeatherData ['time'] [$ generic] = @Jason_Decoded ($ weather file, true); } Return $ this-> WeatherData; }
Comments
Post a Comment