Hacker News new | ask | show | jobs
by maratd 5292 days ago
> it has session handler support so sessions are done completely in memory.

It is unbelievably easy to build session support for other op-code caches. Here is my code for APC:

    if(extension_loaded('session'))
    {
        function ses_open($path, $name)
        {
            return TRUE;
        }
			
        function ses_close()
        {
            return TRUE;
        }
			
        function ses_read($id)
        {
            return (($GLOBALS['session'] = apc_fetch($id)) ? $GLOBALS['session'] : FALSE);
        }
			
        function ses_write($id, $data)
        {
            if(!isset($GLOBALS['session']) || $GLOBALS['session'] != $data)
            {
                if(apc_exists($id))
                {
                    apc_delete($id);
                }
                return apc_store($id, $data);
            }
            else
            {
                return TRUE;
            }
        }
			
        function ses_destroy($id)
        {
            unset($GLOBALS['session']);
            return apc_delete($id);
        }
			
        function ses_gc($max)
        {
            if(
                ($apc = apc_sma_info())
                &&
                ($apc['avail_mem'] / ($apc['num_seg'] * $apc['seg_size'])) < 0.25
            )
            {
                return apc_clear_cache('user');
            }
            else
            {
                return TRUE;
            }
        }
			
        ini_set('session.save_handler', 'user');
        session_set_save_handler('ses_open', 'ses_close', 'ses_read', 'ses_write', 'ses_destroy', 'ses_gc');
    }
The only problem is that this still requires you to compile the session extension. I am looking into ways of working around that, since it's not really used for anything except re-direction.
1 comments

How exactly would you use this with third party code executing on the server that cannot be modified?

eaccelerator's session handler (was) simply built in and requires no modification, just add the one-word setting to your php.ini

You can't modify your code, but you can modify your php.ini?

OK.

PHP has a very nice feature where you can automatically prepend (and append, if you want) a file to all requests. Create a single file, modify your php.ini, done.

I am not telling you that eaccelerator isn't amazing. I am showing you how to get around problems you may run into if you end up using a different op-code cache.