My Web page is using PHP to get JSON data to display the content
And when the page is refreshed, the contents of the JSON are also used
This can cause problems, making the CPU usage of the web space too high
And I know on the Internet can use PHP cache, but do not know how to implement
How do you set it up? Is it possible to add anything directly to the index.php file? How do I set the cache expiration?
I hope we can get answers.
Reply to discussion (solution)
Quick Pick? Does that mean cache?
Can be written like this, note, just provide ideas.
', ' time ' =>0), true);} Read Cache file Contents $cache = Json_decode (file_get_contents ($cache _file), true);//Cache not expired if (time ()-$cache [' Time ']>=$ Expire) {$data = file_get_contents ($data _file);//Read data, here you can write a txt into the content test $cache = array (' data ' + $data, ' time ' = Time ()); File_put_contents ($cache _file, Json_encode ($cache), true); Write Cacheecho ' read data
';} else{//cache has expired echo ' read cache
'; $data = $cache [' Data '];} Echo $data;? >