NGINX + phpFPM load balancer and sessions

I have one question: I am using nginx and PHPFPM . I am using loadbalancer for phpfpm 2 servers .

To synchronize sessions from both phpfpm servers, I used memcached. But when I use memcached, I see that the page is slowing down .

When I use files, since the sessions save the type , the web browser is faster, but the sessions are not synchronized right away (I think the files are offline). I use NFS for sharing sessions.

Any ideas, please, how to synchronize sessions when using nginx loadbalancer for phpfpm servers?

+4
source share
1 answer

The speed increase that you probably see here in PHP using NFS on top of memcached is deceptive in nature. PHP Session Storage by default blocks first-come-first-serve retrieval. This means that two simultaneous requests made for PHP for one session will force the first request to lock the session until PHP is executed, or you explicitly call session_write_close()from your code to release the lock.

But in the file-based session store, PHP relies on flock, which doesn't work on NFS.

NFS protocol (versions 2 and 3) does not support file locking

See this answer on unix stackexchange

, . . NFS flock, , . , , , - , , concurrency .

, session_write_close , , . , PHP (, AJAX).

+2

Source: https://habr.com/ru/post/1653576/


All Articles