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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sefer
Forum Newbie
Posts: 1
Joined: Fri Jul 15, 2011 12:13 pm

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

Post 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.
gooney0
Forum Commoner
Posts: 56
Joined: Fri Jan 21, 2011 1:40 pm
Location: Reston, VA

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

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