Re: Saving the session in a Redis store

2,931 views
Skip to first unread message

Jan Kohlhof

unread,
Feb 27, 2013, 8:02:40 AM2/27/13
to redi...@googlegroups.com
Hi Stephane,

Am 27.02.2013 11:40, schrieb Stephane Eybert:
> My phpinfo() displays:
> Registered save handlersfiles user sqlite redis
> session.save_handlerredisredis
> Redis Supportenabled
> Redis Version2.2.2
did you issue phpinfo() from cli or via apache?
Is it possible that there are 2 php.ini files (one for apache, one for
cli) and the redis extension is only loaded in your cli setup?

I just executed the following snippet without any errors:

<?php
ini_set('session.save_handler', 'redis');
ini_set('session.save_path', 'tcp://localhost:6379');
session_start()

Stephane Eybert

unread,
Feb 27, 2013, 10:40:14 AM2/27/13
to redi...@googlegroups.com, ko...@mathematik.uni-marburg.de
Hi Jan,

First I thank you for the interest in my little issue. I had posted also at http://www.php-forum.com/phpforum/viewtopic.php?f=31&t=22186 but no one was inspired.

Indeed I have two php.ini files, one for the cli and one for the httpd server.

For now I only updated the one for the httpd server and left the cli untouched.

I can see the phpinfo() display and it shows it loaded the redis extension and used it for the session:
My phpinfo() displays:
Registered save handlers files user sqlite redis
session.save_handler redis redis
Redis Support enabled
Redis Version 2.2.2

But when actually using my application I get a 500 error.

I shall try your code snippet and see if I can run it fine.

Kind Regards,

Stephane Eybert

unread,
Feb 27, 2013, 10:47:20 AM2/27/13
to redi...@googlegroups.com
So I tried to run the following script:

ini_set('session.save_handler', 'redis');
ini_set('session.save_path', 'tcp://localhost:6379');
session_start();
print("Done");

And it went fine with a display of Done.

That means there is something wrong with my session handling maybe...

I attached my session handling file.

Kind Regards,

Stephane



On Wednesday, February 27, 2013 12:40:23 PM UTC+2, Stephane Eybert wrote:
Hi,

I don't know if it's the best place to post about this, but I could not find any other forum where to post about my issue as the PHP forum people seem not aware of Redis very much.

I'm trying to save my PHP session in a Redis store.

I coud install edis-2.6.9 and phpredis-2.2.2 on my php-5.3 server.

My phpinfo() displays:
Registered save handlers files user sqlite redis
session.save_handler redis redis
Redis Support enabled
Redis Version 2.2.2

My Redis server is started:
vps13495 src # ./redis-cli*
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379> exit

But when I try to configure my php in the /usr/local/lib64/php53/php.ini file by replacing with the directive:
session.save_handler = files
by the directive:
session.save_handler = redis
and I restart Apache, an http request is replied with a:
HTTP Error 500 (Internal Server Error)

Same thing if I add the directive:
session.save_path = "tcp://vpsXXXXX.ovh.net:6379?weight=1"

Same thing if I add the directive:
session.save_path = "tcp://localhost:6379"

My php log shows:
Error message: session_start() [function.session-start]: Cannot find save handler 'redis' - session startup failed

Any clue ?

Kind Regards,

session.php

Stephane Eybert

unread,
Feb 27, 2013, 10:55:45 AM2/27/13
to redi...@googlegroups.com
First I thought that my directive:

session.save_handler = redis
session.save_path = "tcp://localhost:6379"

in my /usr/local/lib64/php53/php.ini was triggering the 500 error.

But if I have my above directive in place AND also the following code:

ini_set('session.save_handler', 'redis');
ini_set('session.save_path', 'tcp://localhost:6379');

class LibSession {

in my lib/session.php class file then all is well and no more 500 error.

That tells me, for some reason, the redis value for the save_handler directive is ignored in the file /usr/local/lib64/php53/php.ini but not when run within the php script.

Kind Regards,

Stephane Eybert

unread,
Feb 27, 2013, 10:57:16 AM2/27/13
to redi...@googlegroups.com
Commenting out the directive

;session.save_handler = redis
;session.save_path = "tcp://localhost:6379"

in the /usr/local/lib64/php53/php.ini file also works fine if the redis session handler is set up in the php script.

Stephane Eybert

unread,
Mar 1, 2013, 3:23:34 AM3/1/13
to redi...@googlegroups.com
Hello,

I'm embarrassed to say that I had another session.save_path directive sitting a bit below in my php.ini file which was conflicting with my session.save_path = "tcp://localhost:6379" I guess.

After removing that extra session.save_path directive and restarting I didn't get the 500 error any longer, even without the dynamic setup of ini_set('session.save_handler', 'redis'); 
ini_set('session.save_path', 'tcp://localhost:6379'); in my session.php file.

Kind Regards,

Вадим Петров

unread,
Feb 4, 2014, 8:47:55 AM2/4/14
to redi...@googlegroups.com, learni...@gmail.com

For other people, who have same error:
Don't forget remove trailing slash in seve_path, if exist. I spend few hours before understand this >_<
Reply all
Reply to author
Forward
0 new messages