Page 1 of 1

APC page caching in the presence of a dynamic "require"

Posted: Fri Jul 15, 2011 12:24 pm
by sefer
Hi,

I have a question to all those who have used tools such as APC/e-Accelerator and such.

How would these cachers behave in the presence of such code.

Code: Select all

<?php

function my_func($pathname)
{
    require "$pathname";
}

?>
Will the page containing the function above be effectively cached? Assuming that the "$pathname" changes all the time. Does APC cache the "require" statements separately or the page as a whole?
If I pass different values to "$pathname" will the cached bytecode be cast away on every run, effectively rendering it useless?

Thanks,
Sefer.

Re: APC page caching in the presence of a dynamic "require"

Posted: Sat Jul 16, 2011 3:47 pm
by gooney0
As far as I understand it you'd wind up with a cached version of php files as they are used.

In other words the functions.php file would be cached right off the bat. The files that are required will be cached as they are actually used.

When the files change, or you run out of cache memory older files will be flushed.

I don't think you'll have a problem, but you can always test it by seeing if the dates of the cached files change.


On a side note, I don't like to require or include files from within a function. The included file's code will be "trapped" within the space of the function. Maybe this is exactly what you want to do however.