Performance testing of PHP file caching

  • 2020-03-31 20:34:37
  • OfStack

PHP is often cached :
The first is to process the data that needs to be cached into files that PHP can execute directly. When you need to cache data, include it and use it.
The second is to serialize the required data through the serialize function and then save it directly to a file. When you need to use cached data, read the file contents by deserializing them and copy them to the required variables, then use them.

The test results :
In testing, we found that the second method, serialize, was more efficient. (data omitted, finally provided the article address to download, you can test by yourself)

Cause analysis, :
When the include method reads the cache, PHP needs to perform several procedures
1. Read the file
2. Resolve the included files
3. Execute and assign values to variables

When serialize reads the cache:
1. Read the data
2. Deserialize the data content
3. Assign values to variables

Summary analysis :
The first is, include caching
Advantages: increased data confidentiality and security, cache content will not be discovered by the outside world.
Cons: relatively slow.
Purpose: save data that is not available to the system, such as web system Settings, and even MySQL information

Second, serialize the cache
Advantages: faster.
Disadvantages: cache system file path once exposed, cache contents will leak.
Purpose: cache recent articles, related articles, etc., when you don't worry about externally available data.


Related articles: