PHP Quick Pick Problem

Source: Internet
Author: User
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;? >
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.