Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Native session driver
  • Does anybody have a good and secure native session driver for Fuelphp which works with 1.8?
  • You know native sessions don't support concurrency? Which is one of the reasons no native session driver was ever created. It brings your applications to a halt.
  • Having said that, all session drivers contain native session emulation, so your session data should be available in $_SESSION, and updates to it are written back to your session store of choice.
  • ok... I now use the file sessions, and I map the directory to tmpfs...
  • The problem with native sessions is that PHP keeps the session file open with an exclusive lock. Which means you can not do anything concurrently, all processes will need to wait until the lock is released.

    This may not be an issue in simple web application, but is completely breaks anything ajax...
  • Ok and this problem does not occur when using fuelphp file sessions? I really would like to use redis, but I am not a fan of the non-native approach of fuelphp in the redis class... Would be nice if the redis class uses the native extension (php_pecl_redis) if installed and else the current one...
  • I see that v2 will support redis via pecl, is there a backport to v1.8 possible??
  • No, all Fuel drivers supports concurrency. Note that the downside of it is that they are not thread-safe, so you need to take that into account.

    The Redis PECL extension is an optional extension, so we can not expect it to be installed. Which is why Fuel still has a software solution (Redis_Db) which is used by Session and Cache, because they can not depend on an external solution.

    If the extension is loaded, the Redis class will be suppied from the extension. If not, Redis_Db is aliases to Redis by the framework.

    Our Redis_Db class is a fork of Redisent (http://jdp.github.io/redisent/), which is available as a composer package. So there is no backporting needed.
  • Oooh ok I see... thanks.. So in Fuelphp v1 I can just use Redis as my session handler and when I have the pecl extension installed it will automatically use that...?
  • So the whole redis_db module doesn't use the pecl redis extension?
  • Correct. It's a PHP only replacement, because not Fuel itself can not have external dependencies, and because in some environments, users are not able to install PECL extensions by themselfs.

    Don't forget, the PECL extension didn't exist until 2013-04-29, which is the reason we used a Redisent fork in the first place.
  • Ok, but would be nice if the Redis driver would detect it automatically if the pecl extension is installed... I found this nice library https://github.com/colinmollenhour/credis
    Also based on Redisent...
  • Fuel v1 does that already.

    If the PECL extension is detected, the Redis class will be the PECL one, and the internal class can be accessed using Redis_Db. If the PECL extension is not present, Redis_Db is aliased to Redis.

    It would probably be possible to have some autodetection in Redis_Db and switch to the PECL extension, but that would require quite a bit of work to make sure there will be no backward compatibility issues.

    This is effort we don't want to put into v1 anymore, but if you feel it's useful, by all means send in a PR. ;-)

  • I thought Fuel v1 didn't use the pecl redis extension... Can you show me where in the code this is?
  • https://github.com/fuel/core/blob/1.8/develop/classes/fuel.php#L198

    Redis was renamed to Redis_Db in 1.6.1, just to make the PECL extension available.
  • Are you sure this works? It is still using the Redis_Db class I think...

    I have this task:

    public function test()
    {
            var_dump(extension_loaded('redis'));

           \Session::set('123', 123);
    }

    I added a var_dump($config); to the __construct of the Redis_Db class...

    This is my output:
    ====================
    bool(true)
    Array(    [hostname] => 127.0.0.1    [port] => 6379    [timeout] => 5    [database] => 0)====================
    So the Redis_Db driver is being called...
  • If

    class_exist('Redis', false)

    returns true,

    then the PECL extension should be used. You can simply test this in a bit of plain PHP.

    If it returns false (the class isn't loaded), it will alias Redis_Db.
  • /data/home/hverton
    [hverton@catwoman] $ php -a
    Interactive shell

    php > var_dump(class_exists('Redis', false));
    bool(true)

  • php -a
    Interactive shell

    php > var_dump(class_exists('Redis', false));
    bool(true)
  • I see calls to Redis_Db througout the code..
  • HarroHarro
    Accepted Answer
    Ah, you mean that. Yes, internally we have to. Because we need to support Redis for cache even if the PECL extension isn't present.

    As I said, the API is different, so the only way to solve that is to have a single class with a unified API, which uses Redis if present, and Redisent if not. And at the moment we can't be bothered to make that for v1 anymore, AND at the same time maintain backward compatbility.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion