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.