How to load a file to a variable once?

Source: Internet
Author: User
How to load a file to a variable is like this: I have a csv file that contains some key-value ing relationships, which are usually unchanged. The data in this file is required for several different interfaces, so I want to load the file at one time and call other interfaces. I use Singleton mode and _ GLOBALS mode, but I cannot ensure that the load is performed once every time I refresh the interface. What should I do? ------ Solution ------------ How to load a file to a variable only once
The application scenario is as follows:
I have a csv file that contains some key-value ing relationships, which are generally unchanged.
The data in this file is required for several different interfaces, so I want to load the file at one time and call other interfaces.

I use Singleton mode and _ GLOBALS mode, but I cannot ensure that the load is performed once every time I refresh the interface.

What should I do?
------ Solution --------------------
Php is short connection, loading at once and reading is not easy to do
------ Solution --------------------
It is best to paste the code.
------ Solution --------------------
Because each request is a separate process, "common variables" cannot be shared. Data can be stored in a place that can be accessed in a unified manner:
1. File (not your original file .. You can save it as a k v array without reading csv files every time)
2. session.
3. memory (refer to the memory cache principles such as memcached and redis, and common kv storage)
4. database.
5. other storage items that can be shared.
The key is not whether or not to load once. It is about the load performance.

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.