1

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!

2

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.

1
  • 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
1

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.

1
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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