Hacker News new | ask | show | jobs
by ck2 5292 days ago
Has anyone tested the three opcode caches with the 5.4 release candidates?

I am depressed that eaccelerator seems to be fading away - they removed their shared memory functions for their build with 5.3 support.

In my experience eaccelerator is slightly faster and more stable than xcache. As a bonus, when it did have working shared memory functions (under php 5.2) it has session handler support so sessions are done completely in memory (added: without any additional code or modification)

2 comments

> 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.
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.

You should be using APC. It has all the shared memory functions you need and a lot more momentum than eA ever had. Facebook was even hacking on it for a while before HipHop was developed. It's a much better product overall.