erlang_php_session_storage / ErlangSessionHandler.class.php

<?php

class ErlangSessionHandler
{
  protected $host = 'server@127.0.0.1';
  protected $erlang_cookie = 'ABCDEFG';
  protected $conn_timeout = 5;
  
  protected $link = null;
  
  public function open($save_path, $session_name)
  {
    if(null === $this->link)
    {
      $this->link = peb_connect($this->host, $this->erlang_cookie, $this->conn_timeout);
      if(!$this->link)
      {
        throw new Exception(sprintf("Can't connect to the erlang node %s using erlang_cookie %s", $this->host, $this->erlang_cookie));
      }
    }
    return $this->link;
  }
  
  public function close()
  {
    if(is_resource($this->link))
    {
      peb_close($this->link);
    }
  }
  
  public function read($session_id)
  {
    $x = peb_encode("[~s]", array(array($session_id)));
    $result = peb_rpc("session_handler", "read", $x, $this->link);
    $rs = peb_decode($result);
    $data = $rs[0];
    return is_array($data) ? '' : $data;
  }
  
  public function write($session_id, $session_data)
  {
    $x = peb_encode("[~s, ~s]", array(array($session_id, $session_data))); 
    $result = peb_rpc("session_handler", "write", $x, $this->link);
    unset($result);
    return true;
  }
  
  public function destroy($session_id)
  {
    $x = peb_encode("[~s]", array(array($session_id)));
    $result = peb_rpc("session_handler", "destroy", $x, $this->link);
    unset($result);
    return true;
  }
  
  public function gc($max_expirte_time)
  {
    $x = peb_encode('[~i]', array(array($max_expirte_time)));
    $result = peb_rpc("session_handler", "gc", $x, $this->link);
    $rs = peb_decode($result);
    return $rs;
  }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.