How to load a file into a variable only once

Source: Internet
Author: User
How to load a file into a variable only once
The application scenario is this:
I have a CSV file that contains some key-value mapping relationships, which are generally invariant.
Several different interfaces need to use the data in this file, so I want to load it all at once, and the other interface calls.

I use singleton mode and the _globals cannot guarantee the load once, every time the refresh interface is load once.

How do I handle it?
------Solution--------------------
PHP is a short connection, one-time loading and then reading bad do
------Solution--------------------
It's best to post the code to see.
------Solution--------------------
Because each request is a separate process, "normal variables" cannot be shared. You can place data in a place that can be accessed uniformly:
1. In the file (not your original file). Hehe, can actually be saved into a K-v array, do not have to read the CSV file every time
In 2.session.
3. In-Memory (reference memcached, Redis and other memory cache principles, KV common storage)
4. In the database.
5. Other storage that can be shared.
The key is not the load once. It is the performance of load.
  • 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.