8

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

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

I have verified that php is using /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 setting show that I should be using 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 telnet from the box to the end point & port and connect properly, so the instance is able to connect to the memcached server.

Things that we have tried:

  • I have removed the tcp:// from the php.ini file, and that made no difference - sessions are still getting saved in files.
  • We have changed from session.save_handler="memcache" to session.save_handler="memcached"
  • each time we make a change, we stop the httpd server, and then start it again
  • we have even tried rebooting the servers

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

chris
  • 33,326
  • 50
  • 148
  • 232
  • Can you try `memcached` as handler instead of `memcache`? – Daniel W. Jun 12 '14 at 12:42
  • @DanFromGermany: No, this is legacy code and uses memcache for db caches. – chris Jun 12 '14 at 12:52
  • PHP 5.4.29 isn't legacy. Just install the memcached module and give it a try. It won't affect your PHP code anyways. Btw have you restarted PHP (either webserver if it's a module or the fpm if it's fcgi) ? – Daniel W. Jun 12 '14 at 13:34
  • No, our code that uses the memcache lib is the legacy, and would not be easy to update to memcached. I did try configuring just the sessions via php.ini to use the memcached lib, and that did not change anything. And we are stopping and starting the web server, and even tried rebooting the servers - nothing changed. – chris Jun 12 '14 at 13:39
  • just to have gone over the newbie stuff: are you logging startup errors, perhaps displaying them (display_startup_errors) and are you checking your error_log ? – nl-x Jun 12 '14 at 13:45
  • @chris you can use `memcached` in the php.ini for sessions and `memcache` for the legacy PHP code. That's why I said it won't affect your PHP code. – Daniel W. Jun 12 '14 at 13:53
  • Are sessions not working at all? Are working but being saved to disk? Are they working, but saved to some other memcache (EG localhost in stead of elasicache-endpoint) ? – nl-x Jun 12 '14 at 13:54
  • Updated the question with the results of some of these suggestions. – chris Jun 12 '14 at 14:43
  • @chris sure you're looking at the correct php.ini? Maybe the webserver is configured to use another one, then the default one that you see with `php -i`? Try looking in `phpinfo();` which php.ini is being used. – nl-x Jun 12 '14 at 14:57
  • @nl-x: First item in the question is verifying via php -i that it's loading /etc/php.ini – chris Jun 12 '14 at 15:01

2 Answers2

17

OK, we managed to figure out the issue.

First, we created a simple page that spit out phpinfo(). Note that it is important that you run this thru the web server - running php -i DOES NOT include any overrides that apache may add.

Under the session section, the output lists all the directives, and a "Local Value" and a "Master Value".

The local values had:

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

while the master values had:

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

It turns out that there's an override installed by default in /etc/httpd/conf.d/php.conf that specifies the files. This appears to be a Redhat/CentOS/Fedora thing.

Removing those values from php.conf fixed the problem.

chris
  • 33,326
  • 50
  • 148
  • 232
  • A bit what I said in the comments... look at `phpinfo()`. Only I was guessing your configuration would be pointing to another php.ini. So did the php.conf file only overwrite the session setting or did it point to another php.ini file? – nl-x Jun 12 '14 at 22:30
  • @nl-x: the php.conf overrides the settings in php.ini, but only for php run through the web server. That's why we didn't see it running php -i. – chris Jun 13 '14 at 11:51
  • Absolutely brilliant man, I was getting crazy with this, I am using CentOs7 and I can confirm that there is an override in php.conf. – soipo Mar 31 '16 at 15:09
9

Both of the major memcache PHP PECL extensions have session handlers. Either will require you to install a PECL module before use.

The Memcache PECL extension session handler is enabled with the following in php.ini:

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

The Memcached PECL extension session handler is enabled with the following 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.

Koen.
  • 21,087
  • 6
  • 75
  • 76
user3733902
  • 167
  • 3
  • We are using the memcache extenstion, which is installed and working correctly for data caches. It's only the sessions that are not working. – chris Jun 12 '14 at 12:51
  • 2
    Try to use connection url without "tcp://" session.save_path => :11211?persistent=1&weight=1&timeout=1&retry_interval=15 => :11211?persistent=1&weight=1&timeout=1&retry_interval=15 – user3733902 Jun 12 '14 at 13:08
  • Updated the question - we tried this, and it made no difference. – chris Jun 12 '14 at 13:39
  • 1
    Try to change "memcache" to "memcached" in the php.ini like this : session.save_handler = "memcached" – user3733902 Jun 12 '14 at 13:59