3

I'm experiencing an odd Sessions error that unfortunately I've been unable to reproduce locally. In my log file I'm getting the following error randomly upon viewing a page which is referring to this file

session_start(): user session functions not defined on line 84 of file /var/www/vhosts/example.com/symphony/lib/core/class.session.php

From what I can see, this Session handler looks fairly standard so I'm confused as to why this is an error?

The live environment is hosted on Rackspace and is two servers behind a load balancer running PHP 5.4.6 (PHP 5.4.6-1ubuntu1.1 (cli) (built: Nov 15 2012 01:18:34)). From what I know we have two DB servers where one is configured for writes and the other reads (by Rackspace).

My local environment is much simpler, PHP 5.4.10 with a single database, so while I think the environment may be playing a role, I'm very interested into how to fix this issue for the client foremost, but also personally, so the Session class can be made more robust.

brendo
  • 2,914
  • 1
  • 19
  • 22
  • What happens when you try to call Session::open just before that call to session_start()? – Andy Chase Mar 08 '13 at 00:21
  • Hasn't seemed to have any effect unfortunately. I wondered this too, if the `register_shutdown_function` needs to be defined before the session is started. – brendo Mar 08 '13 at 00:42
  • Hm, what happens if you comment out `ini_set('session.save_handler', 'user');`? – Wrikken Mar 08 '13 at 00:57
  • Here is the [error in the source](http://lxr.php.net/xref/PHP_5_4/ext/session/mod_user.c#79). – Jared Farrish Mar 08 '13 at 01:04
  • Commenting `ini_set('session.save_handler', 'user')` out falls back to using Rackspace's default, which results in an error about memcache, `session_start(): Cannot find save handler 'memcache' - session startup failed`. – brendo Mar 08 '13 at 01:06
  • Jared, my C skills are non existent, but does that error seem to indicate the problem is in the user's open handler, ie. Session::open()? – brendo Mar 08 '13 at 01:10
  • Well. C is not my strongpoint, but if you look at it long enough. `8|`. See [this bug report](https://bugs.php.net/bug.php?id=60860) from about a year ago (fixed in ver. 5.3.9). That line I linked to is what that bug report's "fix" was (also, you're seeing an `E_WARNING` correct, not a fatal error? What is the side effect? Any?). I think it's `session_set_save_handler`, but I don't know why it would intermittently occur. Is this error from the Apache error_log? Have you monitored the Apache log while testing? My suspicion is the load balancer, we had a session problem at my last job like this. – Jared Farrish Mar 08 '13 at 01:18
  • Another [relevant bit of the source](http://lxr.php.net/xref/PHP_5_4/ext/session/session.c#511). – Jared Farrish Mar 08 '13 at 01:21
  • Correct, it's a E_WARNING, but that seems to result in a total 500. The error is being written to the CMS's logs, as it implements a custom error handler that pretty much writes all errors to a log file. I suspect the load balancer as well, this issue has only started to occur since it was switched on. Looking at the apache logs is a great idea, thanks for the tip! – brendo Mar 08 '13 at 01:28
  • You might add a check for what `session_set_save_handler()` returns (`bool`) and log when it returns false. If those logs are synonymous with the `E_WARNING`, then there's something in `session_set_save_handler()` execution. Also, have you tried [`session_set_save_handler(..., true)`](http://php.net/manual/en/function.session-set-save-handler.php#refsect1-function.session-set-save-handler-examples) in that page's source? And [here](http://lxr.php.net/xref/PHP_5_4/ext/session/session.c#515), this is what's called when `session.save_handler` is accessed. Look closely; is that a silent error? – Jared Farrish Mar 08 '13 at 01:47

1 Answers1

1

Brendo, the error that you receive when you comment ini_set('session.save_handler', 'user') is most likely caused because you do not have the PHP memcache module installed. If Rackspace configured your servers to save sessions to a memcache server, you may need to enable the PHP memcached module by modifying your php.ini file or the memcache.ini file to have session.save_handler = memcached instead of session.save_handler = memcache.

If the above does not work, you may check to see if you have either one of the PHP modules installed by running dpkg -l | grep memcache to see if either one of the PHP modules are returned.

slade
  • 123
  • 5