4 static function exists($session_id){
7 if($config['memcache_use']){
8 $ret = GLOB
::$mc->get('sid_'.$session_id) ?
true : false;
11 $session_sok = $config['sok_dir'].$config['sok_prefix'].$session_id;
12 return file_exists($session_sok);
18 static function create($client_key){
21 $temp_id = md5(microtime().rand());
23 if($config['memcache_use']){
24 $host_key = 'hostcount_'.$client_key;
25 $count = (int)GLOB
::$mc->get($host_key);
26 if($count > $config['connections_per_host']) return false;
28 // Save the sid into memcached for the ircbot to pick up
29 GLOB
::$mc->add('sid_'.$temp_id, $temp_id);
32 $session_cmd = "{$config['php_path']} {$config['session_script_path']} $temp_id $host_key -h$client_key";
34 $session_status = `
$session_cmd`
;
36 if($session_status != 'ok'){
37 debug("Failed creating session socket with: $session_status");
38 GLOB
::$mc->delete('sid_'.$temp_id);
42 if($config['memcache_use']){
43 GLOB
::$mc->add($host_key, 0);
44 GLOB
::$mc->increment($host_key);
52 static function open($session_id){
55 if($config['memcache_use']){
56 $session_sok = GLOB
::$mc->get('sid_'.$session_id);
57 if(!$session_sok) return false;
59 $session_sok = $session_id;
61 $session_sok = $config['sok_dir'].$config['sok_prefix'].$session_sok;
63 $sok = @stream_socket_client
('unix://'.$session_sok, $errno, $errstr);
65 if(!$sok) return false;
71 static function close($session){
76 static function read($session, $block=true){
77 fwrite($session, json_encode(array('method'=>'read')));
80 stream_set_timeout($session, 0, 100000);
82 stream_set_timeout($session, 120, 0);
84 $data = fgets($session);
93 static function clStart($session_id){
96 if($config['memcache_use']){
97 $session_sok = GLOB
::$mc->get('sid_'.$session_id);
98 if(!$session_sok) return false;
100 $session_sok = $session_id;
102 $session_sok = $config['sok_dir'].$config['sok_prefix'].$session_sok;
104 $sok = stream_socket_server('unix://'.$session_sok, $errno, $errstr);
105 if(!$sok) return false;
112 static function clStop($session){