Asked  9 Months ago    Answers:  4   Viewed   55 times

I have a standard html page that has a few img tags, each of these are pointing to a php file on our server. When the php file is loaded, it saves some data to the session before then generating an image.

This data in the session from each of the scripts is then used in other script further in our application.

The php file to generate the image starts with session_start and when using the native PHP session handler all seems to work great. Each execution is done correctly and the full session data can be retrieved.

If I enable memcache to save the sessions then problems start to occur. It would appear that each of the PHP scripts are executed at the same time and thus when saving to the session only the last to execute actually stores any data.

After further investigation into Memcache I found that the latest stable version does not support session locking, and only in 3.0.4 do they introduce this -

Is it safe to use 3.0.4 when it is only in beta?

Is there any alternative or a way around this issue in 2.2.7?

Please let me know if you would like to see examples of code.




the php-memcached extension supports session locking

the memcache and memcached extensions look syntactically similar so it may not be too much of a headache to give it a try. (memcached has a stable version 2.1.0 released 2012-08-07).

if you are set on using memcache 2.2.7 you will most likely have to implement the lock yourself by setting some "session_is_locked" variable in your session and then releasing/unsetting it when the script is done writing to the session. Then you'd always need to check if that variable is set before continuing with any scripts which write to the session.

Wednesday, March 31, 2021
answered 9 Months ago

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.

Saturday, May 29, 2021
answered 7 Months ago

I would like to thank everybody who participated this question, the answer is the following: in reality memcache (not memcached) as session handler supports comma separated servers as the session.save_path, moreover it supports failover. The error mentioned above Session start failed. Original message: session_start(): Server (tcp 11211) failed with: Connection refused (111) had only 8th (Notice) level. In fact engine just informs you about the fact that one of the servers is unavailable (which is logical, as otherwise how will you know?) and then successfully connects to the second server and using it.

So all of the misunderstanding has been caused by weak documentation, memcache/memcached confusions and paranoid (E_ALL) settings of my custom error handler. In the meantime the issue has been resolved by ignoring notices referring to error Connection refused (111) in the session establishing context

Sunday, September 19, 2021
Ralph Shillington
answered 3 Months ago

File /etc/httpd/conf.d/php.conf had php_value declarations overwriting the local variable.

#php_value session.save_handler "files"
#php_value session.save_path    "/var/lib/php/session”

This solution is a variant of this Stack Overflow answer: What is the difference between local value and master value

When in doubt, use:

grep -lR 'php_value' /etc/
Sunday, October 24, 2021
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :