Comments (12)
Hi and sorry for the late response.
I don't think this is an issue related to Predis per se, but could you create a gist with a code snippet so that I can test your issue in my environment?
Thanks,
Daniele
from predis.
Hi Daniele,
Thanks for replying.
This code works fine:
require "Predis.php";
$single_server = array(
'host' => '127.0.0.1',
'port' => 6379,
'database' => 15
);
$test = array( 'some' => 'value' );
var_dump( $test );
$redisConnection = new \Predis\Client($single_server);
$redisConnection->set('test', serialize( $test) );
var_dump( unserialize( $redisConnection->get('test' ) ) );
whereas this code (adapted and simplified from https://github.com/ivanstojic/redis-session-php/blob/master/redis-session.php) does not work
require "Predis.php";
$redisServer = array(
'host' => '127.0.0.1',
'port' => 6379,
'database' => 15
);
$redisTargetPrefix = "session:php:";
session_set_save_handler(
'redis_session_open',
'redis_session_close',
'redis_session_read',
'redis_session_write',
'redis_session_destroy',
'redis_session_gc');
function redis_session_read($id) {
global $redisServer, $redisTargetPrefix;
$redisConnection = new \Predis\Client($redisServer);
return base64_decode($redisConnection->get($redisTargetPrefix . $id));
}
function redis_session_write($id, $data) {
global $unpackItems, $redisServer, $redisTargetPrefix;
$redisConnection = new \Predis\Client($redisServer);
$ttl = ini_get("session.gc_maxlifetime");
}
function redis_session_destroy($id) {
global $redisServer, $redisTargetPrefix;
$redisConnection = new \Predis\Client($redisServer);
$redisConnection->del($redisTargetPrefix . $id);
}
function redis_session_open($path, $name) {}
function redis_session_close() {}
function redis_session_gc($age) {}
session_start();
$_SESSION['animal'] = 'cat';
I get the following line in Apache's error log:
PHP Fatal error: Class 'Predis\\Client' not found in /var/www/xslt/testPredis3.php on line 31
from predis.
Hi jerje,
no luck so far with trying to reproduce this issue. I've tested your script on ArchLinux with PHP 5.3.4 and MacOS X with PHP 5.3.3 (both using the suhosin patch installed as a module) but I couldn't get any error out of it and the session handler works as expected.
Do you have any update on your side?
from predis.
Hi Daniele,
Apologies for the delay in replying.
I upgraded Ubuntu and php -v is returning
PHP 5.3.3-1ubuntu9.1 with Suhosin-Patch (cli) (built: Oct 15 2010 14:17:04)
but I am still getting the same error. I had a look around to see if anyone had
reported similar bugs but couldn't find anything.
I'll try it on some other machines to see if I can narrow it down.
from predis.
Don't worry, no problem.
In the next few days I will try on an Ubuntu virtual machine with Apache to replicate the same environment, and see if I can get the same error out of it.
from predis.
I can confirm the same error on CentOS 5.5 with self-compiled PHP 5.3.5 and suhosin patch using the above test code. I don't get the error using MacPorts PHP 5.3.5 with suhosin on my dev machine.
I believe the error occurs because session_write_close is not called when your script ends, but after all of your objects have been destroyed. You can fix (temporarily) the issue by calling session_write_close() at the end of your script.
More here: http://us.php.net/session_set_save_handler
from predis.
@rquigley thanks, I will try also with CentOS and the same configuration.
from predis.
As an alternative you can try to add session_write_close() into the __destruct() method of the redis client class for example.
from predis.
@Seldaek: maybe a more clean solution could consist in adding a shutdown callback in the script that contains the code for the session handler:
function session_shutdown() {
session_write_close();
}
register_shutdown_function('session_shutdown');
@Jerje: you might want to try the above mentioned tricks, but can you also try to alias \Predis\Client to see if the problem can be somewhat related to namespacing issues? It's highly unlikely, but still...
use \Predis\Client as Predis_Client;
Unfortunately I still hadn't the time to test this under CentOS :-(
from predis.
Any news? I wasn't able to reproduce it and I'm pretty sure this is a bug in certain older versions of PHP that has been since resolved.
I will leave this issue open for a few days, then I will close it if no further feedback is provided.
from predis.
Hey,
Sorry again for the delay in replying.
I retried this and as nrk pointed out it seems to be a bug in older versions of PHP.
I just checked on Ubuntu and using PHP 5.3.2-1ubuntu4.7 it seems to work just
fine.
Thanks for all the feedback.
from predis.
Thanks for the follow up, jerje.
It's reassuring to know that it was a bug of PHP after all.
from predis.
Related Issues (20)
- Save in local cache (presumably with an expiration)
- Cache configuration objects (to support memory, number of keys, etc)
- [v3] cherry-pick opt out setinfo for v3 HOT 1
- Update CLIENT-SETINFO to support suffixes HOT 1
- Missing BITFIELD_RO support HOT 1
- psubscribe seems to swallow exit, exceptions, disconnect, quit calls HOT 4
- Add support for GEOSHAPE index fields and WITHIN and CONTAINS query operators
- Error while writing bytes to the server HOT 3
- Error on RPOP expects exactly 1 argument, 2 given HOT 2
- Explain `expireResoluton` for `SET` HOT 1
- Improve connection speed by running fewer commands
- Question: the `ClientInterface::eval` signature and PhpRedis HOT 1
- Connect to Sentinel with username: how to implement right ? HOT 3
- Add support for HSCAN [NOVALUES]
- Add command filter for CLIENT KILL to support maximum age via [MAXAGE] option
- Support XREAD, XREADGROUP reading from last message of stream
- Supporting redis unstable commands
- Consider master-link-status state when selecting slaves
- PSR-7 compatible stream abstraction HOT 4
- Cannot use 'EVAL_RO' with redis-cluster HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from predis.