Today, when redis is automatically disabled, there is a problem of reading the cache function: first go to redis or memcache to read the cache, and then return to read the array. If not, read the file cache, if yes, the file array is returned, and then written to redis or memcache cache and file cache. The problem is that after redis is closed, it will always read the file
Today, when redis is automatically disabled, there is a problem of reading the cache function: first go to redis or memcache to read the cache, and then return to read the array. If not, read the file cache, if yes, the file array is returned, and then written to redis or memcache cache and file cache. The problem is that after redis is closed, it will always read the file
Today, when redis is automatically disabled, there is a problem with reading the cache function:
Read from the redis or memcache cache first. If yes, the system returns the read array. If no, it reads the File Cache. If yes, the system returns the array of the file and writes it to the redis or memcache cache and the File Cache.
The problem is that after redis is closed, it will always read the file Cache and write new data to the file.
$ Strlen = file_put_contents ($ cachefile, $ arr); // write the cached File
If LOCK_EX is not used here, when using this function in high concurrency, it may appear that one php has not completely written the file, and the other php will read it, the result shows that the returned content is not an array, and a new content is written, which is repeatedly written, read, error, and written.
At this time, it depends on the situation. If the cached file corresponds to a different name, concurrent operations may not happen. LOCK_EX can be avoided. After all, it will consume performance. When LOCK_EX does not consume more, it is an endless loop.
Original article address: Add a lock to your PHP write function file_put_contents. Thank you for sharing it with me.