PHP sessions not stored in memcache

Running an application using php 5.4 on AWS using Amazon Linux.

The PHP version is PHP 5.4.28. memcache lib installed from the AWS repository - php54-pecl-memcache-3.0.8-1.11.amzn1.x86_64

I checked that php uses /etc/php.ini:

[ root@ip-xx.xx.xx.xx ]# php -i | grep Config Configuration File (php.ini) Path => /etc Loaded Configuration File => /etc/php.ini 

The parameter shows that I should use memcache:

 [ root@ip-10-40-17-119 etc]# grep "^session.save" php.ini session.save_handler="memcache" session.save_path="tcp://<elasticache-endpoint>:11211" [ root@ip-10-40-17-119 php.d]# php -i | grep session.save session.save_handler => memcache => memcache session.save_path => tcp://<elasicache-endpoint>:11211?persistent=1&weight=1&timeout=1&retry_interval=15 => tcp://<elasticache-endpoint>:11211?persistent=1&weight=1&timeout=1&retry_interval=15 

I can install telnet from the box to the endpoint and port and connect correctly so that the instance can connect to the memcached server.

What we tried:

  • I deleted tcp: // from the php.ini file, and it didn’t matter - the sessions are still stored in the files.
  • We changed from session.save_handler = "memcache" to session.save_handler = "memcached"
  • every time we make changes, we stop the httpd server and then start it again
  • we even tried to restart the servers

No matter what we tried, the sessions are stored on disk in / var / lib / php / sessions. Is there something I'm missing, or is this a known issue of 5.4 or AWS?

+7
php memcached session centos libmemcache
source share
2 answers

OK, we managed to find out the problem.

First, we created a simple page that spits out phpinfo (). Please note that it is important that you run this through a web server - running php -i does NOT include any overrides that apache can add.

In the session section, the output lists all the directives, as well as the Local value and Main value.

Local values ​​had:

 session.save_handler files session.save_path /var/lib/php/session 

while the main values ​​were:

 session.save_handler memcache session.save_path tcp://<endpoint>:11211 

It turns out that by default, the /etc/httpd/conf.d/php.conf file specifies an override that defines files. This is similar to the Redhat / CentOS / Fedora thing.

Removing these values ​​from php.conf fixes the problem.

+13
source share

Both major PHP PECL memcache extensions have session handlers. Or you will need to install the PECL module before use.

Memcache The PECL extension session handler is included in php.ini:

 session.save_handler = "memcache" session.save_path = "tcp://memcacheServerAddressHere:11211?persistent=1&weight=2&timeout=2&retry_interval=10" 

Memcached PECL extension session handler is included in php.ini:

 session.save_handler = "memcached" session.save_path = "memcacheServerAddressHere:11211" 

Note that the Memcache extension appears to allow more configuration of the Memcache environment.

+6
source share

All Articles