Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Which of these 2 is easier/faster for a Linux server running Apache to process?

A) A symlink pointing to a php file:

file-sym.php ---> file-orig.php

B) A PHP file (file-inc.php) including another PHP file (file-orig.php) like so:

Contents of file-inc.php

<?php 
    include('file-orig.php'); 
?>

Curious if anyone has done any benchmarks!

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

My gut reaction tells me the symlink will be faster, because you will have to read less data when handling the first link in that chain. I'm not sure there is much of a difference though, try benching the two to see a difference.

A)

  1. read file (on ext2+ symbolic links are included in the inode, hence only one seek)
  2. read other file
  3. execute php

B)

  1. read file
  2. execute php
  3. read other file
  4. execute php

The include() variant is good for Windows users I guess, since they can't have symlinks on their systems.

share|improve this answer
    
awesome, makes sense and glad you pointed out that there would only be one seek on ext2+ systems. –  filip Dec 21 '10 at 18:33
add comment

Many administrators disable apache symlinks for security and performance reasons.

For performance purposes, please view this page on apache tuning: http://httpd.apache.org/docs/2.2/misc/perf-tuning.html

Wherever in your URL-space you do not have an Options FollowSymLinks, or you do have an Options SymLinksIfOwnerMatch Apache will have to issue extra system calls to check up on symlinks. One extra call per filename component. For example, if you had:

 <Directory />
 DocumentRoot /www/htdocs 
 Options SymLinksIfOwnerMatch
 </Directory>

and a request is made for the URI /index.html. Then Apache will perform lstat(2) on /www, /www/htdocs, and /www/htdocs/index.html. The results of these lstats are never cached, so they will occur on every single request.

You can see how symlinks can be an exponential performance problem depending on your environment and code.

share|improve this answer
    
that's quite interesting. Would you suggest that the PHP include(); method may overall be better if symlinks are turned off? –  filip Dec 21 '10 at 20:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.