Let say I use Redis to store my session in PHP (previously I use mySql 5.0), and the Redis Server is in different server from the PHP App server. So, when there is request coming in, session will be created / load from Redis, it will take one socket from the PHP App Server. When if there is 100 concurrent requests, will there be 100 sockets to Redis? or just one?
Share
Redis doesn’t have any built-in connection pooling and I don’t think current Redis bindings for PHP offer anything like that, so by default there would be one socket/connection opened per PHP thread. So if your web server (Apache/Nginx/IIS) tries to service those 100 concurrent requests with 100 PHP threads, there would be 100 connections to Redis.
If the server is instead configured to limit the number of PHP threads (more common I think) then those 100 concurrent requests will be serviced by maybe 5 PHP threads (each handling ~20 requests, one-after-the-other) which means at any time there would be 5 open connections to Redis.If they are not persistent connections then you’ll have 100 connections to Redis and 100 disconnects, with only 5 open at any given moment. If the connections are persistent then you’ll have just 5 connections open, closing only when if the parent PHP thread terminates.