apache - hard links between php files in different directories, what should be the expected behaviour of __FILE__ -


i have 2 websites identical in structure. index.php file needs generate different content depending on domain page being served from. using apache 2.2 , created 2 virtual hosts using 2 different folders under /var/www (/var/www/site.domain.com , /var/www/site.domain.ca)

i using file obtain full path of executing index.php , depending on path output correct content.

since files same, wanted use links make editing file easier, instead of editing 1 of index.php, copying other directory, wanted editing either of files update other.

i used cp -al command copy hard links:

cp -al /var/www/site.domain.com /var/www/site.domain.ca

the problem when access index.php file in 1 site vs. other, file variable not reflect path of index.php file executing. depending on domain visit first, file reflect path of domain.

i try using getcwd see if works, can explain why happening. shouldn't file reflect current script that's executing.

these hard links, not soft links.

is apache caching script, apc source of problem?

update: getcwd() worked, seems return correct current directory.

that's how hardlinks work. system not going scan through entire filesystem try , figure out alternative names file. hardlink that.. hard. "this official, unchanging, immutable name file".

e.g:

$ cat z.php <?php echo __file__, "\n" $ mkdir subdir $ cd subdir $ ln ../z.php hardlink.php $ ln -s ../z.php softlink.php $ php hardlink.php /home/marc/test/subdir/hardlink.php $ php softlink.php /home/marc/test/z.php 

note hardlink displays location of hardlink itself, while softlink (aka symlink) displays target of link, not link itself.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -