Cupidvogel Posted September 8, 2012 Share Posted September 8, 2012 Hi, can anybody explain what is meant by realpath in PHP? In particular, I was studying the documentation for the clearstatecache function in the PHP manuals, it has an optional first boolean parameter named $clear_realpath_cache, which determines whether or not to clear the realpath cache for the file mentioned as the 2nd parameter. So what difference will the absence of the first parameter make? Quote Link to comment https://forums.phpfreaks.com/topic/268164-meaning-of-realpath-in-php/ Share on other sites More sharing options...
Pikachu2000 Posted September 8, 2012 Share Posted September 8, 2012 I thought I had an answer for you, but I guess I don't. It defaults to FALSE, but I'm really not sure why you'd want to set the first parameter to TRUE. Maybe I can run a few scenarios later and figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/268164-meaning-of-realpath-in-php/#findComment-1376346 Share on other sites More sharing options...
Cupidvogel Posted September 8, 2012 Author Share Posted September 8, 2012 Thanks. Please do it and explain what is happening. I am too new to PHP to do these tests myself! Quote Link to comment https://forums.phpfreaks.com/topic/268164-meaning-of-realpath-in-php/#findComment-1376348 Share on other sites More sharing options...
ignace Posted September 8, 2012 Share Posted September 8, 2012 realpath returns the "real" absolute path of whatever you put in. If you pass it a relative path it turns it into an absolute one: realpath('/User/Ignace/PhpStormProjects/foo/baz/../../foo'); // returns /User/Ignace/PhpStormProjects/foo If the passed in argument points to a linked directory then it resolves the link and return the underlying directory, for example on my Mac the directory php5 points to the latest php5 version: realpath('/usr/local/php5'); // returns /usr/local/php5-080920122231 Since all IO operations are "slow" realpath() caches everything it resolves. It uses APC for example if you have it enabled to speed up lookups across all visitors. That's what I heard/know about realpath(). Quote Link to comment https://forums.phpfreaks.com/topic/268164-meaning-of-realpath-in-php/#findComment-1376353 Share on other sites More sharing options...
Cupidvogel Posted September 8, 2012 Author Share Posted September 8, 2012 So part from the caching bit, this is just like the canonical method of the URI module in Perl which normalizes URLs, resolving unnecessary up and down traversals within the address to give it in a compact form? Quote Link to comment https://forums.phpfreaks.com/topic/268164-meaning-of-realpath-in-php/#findComment-1376356 Share on other sites More sharing options...
kicken Posted September 9, 2012 Share Posted September 9, 2012 So part from the caching bit, this is just like the canonical method of the URI module in Perl which normalizes URLs, resolving unnecessary up and down traversals within the address to give it in a compact form? I don't really know perl but that sounds about right. You give it a relative path and it will determine what the actual full path is to the given file. This includes resolving things like symlinks on linux. Regarding the caching stuff, when you do something that causes PHP to lookup a stat() on a file it will cache that information so that future calls needing the same info for the same file can be resolved quickly. I find it is generally not necessary to call the clearstatcache function, but it's there if you need it. afaik the cache is only valid for the currently executing request so if you do something with a file in request A, then do something with that same file in request B, both will go to the file for any information rather than a cache. Clearing the cache would only be necessary if you're doing something something with the file multiple times in the same request. Quote Link to comment https://forums.phpfreaks.com/topic/268164-meaning-of-realpath-in-php/#findComment-1376470 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.