jmathai / epiphany

A micro PHP framework that's fast, easy, clean and RESTful. The framework does not do a lot of magic under the hood. It is, by design, very simple and very powerful.
https://github.com/jmathai/epiphany
Other
686 stars 139 forks source link

How to use getSession() with non default Memcached #61

Closed cr1st1an closed 11 years ago

cr1st1an commented 11 years ago

I'm not sure I understand how to use the EpiSession with memcached:

Any pointers?

jmathai commented 11 years ago

You're close. The docs should be more clear on this.

EpiSession::employ(
  array(
    EpiSession::MEMCACHED, 
    getConfig()->get('memcached')->host, 
    getConfig()->get('memcached')->port, 
    getConfig()->get('memcached')->compress, 
    getConfig()->get('memcached')->expiry
  )
);
cr1st1an commented 11 years ago

I don't believe that works, it defaults to a PHP session, since the employ function on Epi Session only reads the first parameter:

From EpiSession.php

  public static function employ(/*$const*/)
  {
    if(func_num_args() === 1)
    {
      self::$employ = func_get_arg(0);
    }

    return self::$employ;
  }

function getSession()
{
  $employ = EpiSession::employ();
  if($employ && class_exists($employ))
    return EpiSession::getInstance($employ);
  elseif(class_exists(EpiSession::PHP))
    return EpiSession::getInstance(EpiSession::PHP);
  elseif(class_exists(EpiSession::APC))
    return EpiSession::getInstance(EpiSession::APC);
  elseif(class_exists(EpiSession::MEMCACHED))
    return EpiSession::getInstance(EpiSession::MEMCACHED);
  else
    EpiException::raise(new EpiSessionException('Could not determine which session handler to load', 404));
}
jmathai commented 11 years ago

@cr1st1an You're right. I had a local modification which wasn't pushed to master. Do you mind updating and confirming if this issue is resolved using the code I provided in my earlier comment?

cr1st1an commented 11 years ago

Awesome, thanks! It's working now. I did a bit of cleanup for the EpiCache_Memcached and EpiSession_Memcached classes, including the expiry issue that ignores the setting. Will send a pull request.

cr1st1an commented 11 years ago

Hi! I believe EpiCache has this same issue

cr1st1an commented 11 years ago

Bump!