core icon indicating copy to clipboard operation
core copied to clipboard

Realpath doesn't resolve symlinks properly

Open jesseobrien opened this issue 15 years ago • 6 comments

This is in regards to https://github.com/fuel/fuel/blob/1.1/develop/public/index.php

define('APPPATH', realpath(__DIR__.'/../fuel/app/').DIRECTORY_SEPARATOR);
define('PKGPATH', realpath(__DIR__.'/../fuel/packages/').DIRECTORY_SEPARATOR);
define('COREPATH', realpath(__DIR__.'/../fuel/core/').DIRECTORY_SEPARATOR);

I'm not sure if it's related to this bug in PHP or not. This post and this post lead me to believe it's not that bug, it's the issues with caching. The issue seems to be stemming from realpath() and it's caching of paths, which might actually change if symlinks are moved or folder structures are modified. This caching happens per thread. I'm not sure if there's a better solution than realpath here or not though. The recommended solution is to restart apache in between upgrades to fully clear the cache.

I'm on 5.3.8 btw:

jesse@Jesse-Debian:/var/www/fuel$ php -v PHP 5.3.8-2 with Suhosin-Patch (cli) (built: Sep 12 2011 07:28:26)

jesseobrien avatar Oct 21 '11 22:10 jesseobrien

Does that mean that if you add a clearstatcache() to your index.php, the issue is solved?

WanWizard avatar Oct 22 '11 10:10 WanWizard

I believe that will only fix it for that particular thread.

It turns out realpath()’s cache is per-thread, so even though I was clearing it in the apache thread that was doing the upgrade, it still had old data in other apache threads.

jesseobrien avatar Oct 22 '11 14:10 jesseobrien

True, but if you add it to index.php, it will flush the cache for that thread before realpath() is used.

Downside is that it will permanently disable file stat caching, which might have other side effects.

WanWizard avatar Oct 22 '11 16:10 WanWizard

clearstatcache's first argument needs to be set to true to clear the realpath cache and clearstatcache's second argument can clear the cache for a specific file

So base on the documentation, I think 3 calls to clearstatcache could do the trick, no?

Savageman avatar Oct 24 '11 08:10 Savageman

I think we should just document this in the troubleshooting section, so people that use symlinks can add this to the index.php themselfs. I don't feel this kind of workarounds should be in the framework. @dhorrigan?

WanWizard avatar Oct 24 '11 09:10 WanWizard

We have decided not to add any code to the framework to fix this for the few users that have this problem.

A paragraph is added to the troubleshooting section of the documentation, explaining this issue and providing possible solutions.

WanWizard avatar Oct 24 '11 10:10 WanWizard