Home > Backend Development > PHP Tutorial > Operation and maintenance - PHP encounters occasional session loss when using memcached to save sessions?

Operation and maintenance - PHP encounters occasional session loss when using memcached to save sessions?

WBOY
Release: 2023-03-01 17:00:02
Original
1100 people have browsed it

It is an occasional loss. For example, the $_SESSION I read during the second ajax request was an empty array. The $_SESSION value was normal again during the third request. However, I once initiated five ajax requests at the same time on a certain page. When there are six requests, there is a high probability that a certain session will be lost. Please help, how to solve it

php.ini is as follows

<code>session.save_handler = memcached
session.save_path = "127.0.0.1:11211"</code>
Copy after login
Copy after login

The running environment is in my vagrant virtual machine. PHP and memcahe are installed in this virtual machine. PHP is 5.6 and memcache is 1.4.4. The strange thing is that when I save the session as a file, I don’t encounter the problem of session loss

Reply content:

It is an occasional loss. For example, the $_SESSION I read during the second ajax request was an empty array. The $_SESSION value was normal again during the third request. However, I once initiated five ajax requests at the same time on a certain page. When there are six requests, there is a high probability that a certain session will be lost. Please help, how to solve it

php.ini is as follows

<code>session.save_handler = memcached
session.save_path = "127.0.0.1:11211"</code>
Copy after login
Copy after login

The running environment is in my vagrant virtual machine. PHP and memcahe are installed in this virtual machine. PHP is 5.6 and memcache is 1.4.4. The strange thing is that when I save the session as a file, I don’t encounter the problem of session loss

The hit rate of memcache cannot be so low. Is the memcache full? Or are multiple machines used in the background, and the memcache used for session storage is not shared?
The specific problem depends on the code

Session has a concurrency consistency problem. You can lock when writing data and release the lock after writing
Please see the explanation here: http://justcoding.iteye.com/b...

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template