note 117795 added to function.symlink
| From: | raat1979 at gmail dot com | Date: | Tue, 11 Aug 2015 12:20:02 +0000 |
| Subject: | note 117795 added to function.symlink | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203308@lists.php.net to get a copy of this message | ||
Be warned that at least with php 5.3 on windows 2008 R2 the symlink function is effected by the
statcache.
I got error 183 indicating the link existed. While the symlink was actually moved to a different
location by another process and would certainly not exist anymore.
Calling clearstatcache with a filename does not work. Most probably as the filename is converted to
a device path (e.g. "\Device\HarddiskVolume1\D-Drive\www\pp\#static\index.html") which is
a requirement for the windows call.
easiest is to just call clearstatcache without a filename to resolve the issue.
if you really want to call clearstatcache with a filename you could use readlink on the already
deleted symlink (that still lives in the statcache) to get the filename.
For example something like this:
<?php
if(@symlink('d:/www/pp/#static/index.html','d:/www/index.html')===false){
//link failed, perhaps a statcache issue? We try to get the target, if it is a statcache issue this
should work just fine
if(($rl = @readlink($target))===false) return false; //not a cache issue as stat on a non-existing
file failed, something else must be wrong...
//clear the stat cache for the actual target, strangely enough this works even-though this is the
target and not the symlink to be created (*)
clearstatcache(true,$rl);
if(@symlink($source,$target) ===false) return false; //can't create the symlink
?>
*It looks for PHP on windows like the statcache is maintained on the target instead of the actual
symlink (this would ease in getting the file properties and limit the size of the statcache)
----
Server IP: 72.52.91.14
Probable Submitter: 89.20.95.34
----
Manual Page -- http://php.net/manual/en/function.symlink.php
Edit -- https://master.php.net/note/edit/117795
Del: integrated -- https://master.php.net/note/delete/117795/integrated
Del: useless -- https://master.php.net/note/delete/117795/useless
Del: bad code -- https://master.php.net/note/delete/117795/bad+code
Del: spam -- https://master.php.net/note/delete/117795/spam
Del: non-english -- https://master.php.net/note/delete/117795/non-english
Del: in docs -- https://master.php.net/note/delete/117795/in+docs
Del: other reasons-- https://master.php.net/note/delete/117795
Reject -- https://master.php.net/note/reject/117795
Search -- https://master.php.net/manage/user-notes.php