On the server, if all user sessions are saved to the temporary directory, the security and efficiency of the server will be reduced, and it will be very slow to open the site stored on the server. On Windows, the default Session server file of PHP is stored in C: \ WINDOWS \ Temp,
1. session temporary file
On the server, if all user sessions are saved to the temporary directory, the security and efficiency of the server will be reduced, and it will be very slow to open the site stored on the server. On Windows, PHP stores default Session server files in C: \ WINDOWS \ Temp. if the number of concurrent accesses is large or the number of sessions is too large, there will be a large number of session files similar to sess_xxxxxx in the directory. a large number of sessions in the same directory will lead to performance degradation and may lead to a file system error. In this case, PHP provides a better solution. Use functions in phpSession_save_path ()This problem can be solved.
Using the php function session_save_path () to store session temporary files can alleviate server efficiency reduction and slow site opening caused by temporary file storage. the instance code is as follows:
Note: The session_save_path () function should be called before the session_start () function.
2. session cache
Session cache temporarily stores the content on the webpage to the Temporary Internet Files folder on the client and sets the cache time. After browsing the webpage for the first time, some content of the page will be temporarily stored in the temporary folder of the client within the specified time, so that the next time you visit this page, you can directly read the content in the cache to improve the browsing efficiency of the website.
Role of Session cache
(1) reduce the frequency of accessing the database. The speed at which applications read persistent objects from the cache is obviously better than that of retrieving data from the database.
(2) when persistent objects in the cache are cyclically associated, the Session will ensure that there is no endless loop accessing the object graph and JVM stack overflow caused by the endless loop.
(3) ensure that the relevant records in the database are synchronized with those in the cache. When the Session clears the cache, it will automatically perform a dirty data check (dirty-check). if it finds that the objects in the Session cache are inconsistent with the corresponding records in the database, the database is updated based on the latest object attributes.
The session cache uses the session_cache_limiter () function. the syntax format is as follows:
session_cache_limiter(cache_limiter)
The cache_limiter parameter is public or private. At the same time, the session cache is not displayed on the server but on the client.
The cache time is set using the session_cache_expire () function. the syntax format is as follows:
session_cache_expire(new_cache_expire);
The cache_expire parameter is the session cache time, measured in minutes.
Note: The two session cache functions must be called before the session_start () function; otherwise, an error occurs.
The following code describes the session cache page process through an instance:
The above are the details of session temporary files and cache instructions in php. For more information, see other related articles in the first PHP community!