6

I am building a framework where product instances use the main framework files, until there is a copy of it's own version of that file. To achieve this I have done the following:

set_include_path(MY_PRODUCT_ROOT.'/' . PATH_SEPARATOR . MY_FRAMEWORK_ROOT.'/');

So if I call include('view-users.php'); it will first look in MY_PRODUCT_ROOT for /view-users.php and if that's not found, it will then look to MY_FRAMEWORK_ROOT/view-users.php.

This procedure is working very nicely until I add files to the product root. I know that PHP/Apache is caching the includes and one would think to run clearstatcache(true); to clear any status caching. PHP likely uses file_exists inside it's include(); and thinks the new file still does not exist. I have tried restarting Apache with no effect.

Unfortunately running clearstatcache(true); does not help either. Only once I have deleted MY_FRAMEWORK_ROOT/file does it think to clear cache and try again, thus finding MY_PRODUCT_ROOT/file.

Im a little stumped, I know we need to refresh PHP/Apache's understanding of whether the file(s) exist or not, but clearstatcache(true); is not helping...

Any ideas?

UPDATE: Correction, restarting Apache seems to help now. I reiterate that this only occurs when trying to ADD a file to MY_PRODUCT_ROOT, to overlap an existing MY_FRAMEWORK_ROOT file, for customization

UPDATE: Development environment is Zend Server CE PHP 5.3.14 on Windows, Production environment Centos linux httpd, PHP 5.3+. The fact that Zend optimizer is enabled on my dev environment could have an effect, Also not using APC or any other caching scripts

6
  • To be more precise, restarting apache only works while calling clearstatcache. I actually have to delete the framework file, then reload the page, and put the framework file back Commented Nov 6, 2012 at 9:00
  • 1
    do you have apc cache enabled? (or another optcode cache) Commented Nov 6, 2012 at 9:03
  • I was also unable to reproduce your problem on php-5.3.3 and apache 2.2.16. Could you state more information on your environment? Commented Nov 6, 2012 at 9:13
  • @NikoSams nope not using APC caching Commented Nov 6, 2012 at 9:52
  • @Lars I am using ZendServer PHP 5.3.14 (dev enviro) will be running on Centos server PHP 5.3+ Now that i see php info, it may have something to do with Zend Optimizer... will have a look Commented Nov 6, 2012 at 9:53

1 Answer 1

2

Zend Optimizer+ speeds up PHP execution by opcode caching and optimization. It stores precompiled script bytecode in shared memory. This eliminates the stages of reading code from the disk and compiling it on future access. For further performance improvements, the stored bytecode is optimized for faster execution.

This is caching the file contents found in the includes, thus clearstatcache does not work. I have disabled my Zend Optimizer and it works now.

Sign up to request clarification or add additional context in comments.

1 Comment

Please note that you may accept your own answer. Also, could you please check, if a clearstatcache(true, true) does a difference when the Zend Optimizer+ is active? If not, you should file a bug report at the product homepage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.