Hello,
I believe I've hit a memory leak in eaccelerator_get() while trying to benchmark some memory caching classes i've built based on different packages/tools (memcache, native shm, eaccelerator, etc).
I'm using Debian sarge with apache 1.3, php 5.1.2 from dotdeb.org and the latest eaccelerator snapshot (eaccelerator-svn200603061029) compiled with --with-eaccelerator-shared-memory to enable key caching through eaccelerator_put() and eaccelerator_get().
The code below should not suffer any memory leaks but it does:
<?php
function ea ($str)
{
eaccelerator_put("testkey", $str);
for ($i = 0; $i < 1e5; $i++)
{
$r = eaccelerator_get("testkey");
}
return $r;
}
$str = str_repeat("1234567890", 1024); // 10 KB
$r = ea($str);
echo strlen($r);
?>
Yields:
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 10241 bytes) in /var/www/test/ea2.php on line 9
The native php SysV shared memory module works just fine:
<?php
function shm ($str)
{
$shm_key = ftok(__FILE__, chr(1));
$shm_id = shm_attach($shm_key, 256 * 1024, 0666); // a 256 KB block
shm_put_var($shm_id, 1, $str);
for ($i = 0; $i < 1e5; $i++)
{
$r = shm_get_var($shm_id, 1);
}
return $r;
}
$str = str_repeat("1234567890", 1024); // 10 KB
$r = shm($str);
echo strlen($r);
?>
Yields:
10240
as expected.
I saw eaccelerator_get() defined in cache.c is used in the session functions too when EA is set as the session handler but also in content caching and this memory leak looks quite nasty!
Anyway, eaccelator is a superb extension. Beats all other php cachers/optimizers I've tried.
Thank you and keep up the good work!