7

I tried to find an existing question for this already, but couldn't find a good match.

As part of my deploy process for my public facing sites, I am using symlinks to swap between versions of the web application.

For instance, I have a vhost abc.com which has a docroot here: /var/www/abc.com

The docroot itself (/var/www/abc.com) is a symlink to the application's web-accesible directory (/var/www/package/buildX/web)

When I deploy a new build, I simply swap out the symlink and replace with another symlink to the new build.

The question I have is, what is the performance overhead (or concerns I should have) with using symlinks for an Apache docroot

2
  • 1
    Did you ever have any problems with a race condition where previous existing apache processes were connected to buildX's file path through the symlink and then when you swapped symlinks and moved the old directory somewhere else, kept getting PHP Fatal Errors like Unknown: failed to open stream: No such file or directory in Unknown on line 0?
    – Benno
    Jan 4, 2016 at 23:56
  • UPDATE: Nevermind, I think its due to PHP caching real file paths in realpath_cache_get(). Running clearstatcache(true) seems to fix it.
    – Benno
    Jan 5, 2016 at 1:03

2 Answers 2

7

The first issue is, are all of these files in the same filesystem or physical storage device? If so, the difference between a direct reference and a symlink will be nearly impossible to detect.

You need to think in orders of magnitude here. Your application is probably underpinned by a scripting language and a database. Those elements of the application will be the limiting factor, not a minor filesystem feature. Jeff Atwood explains this best in this blog post.

0
3

Don't worry about symlink performance hit. Practically everything else will be a bottleneck before that one. Resolving a symlink does not take too many CPU cycles; running your PHP script, handling the database queries and result sets, possibly using modules like Apache's mod_security will be the real bottle neck.

In theory you could optimize something if everything your server serves is static content; even then, tuning the web server and/or kernel parameters and scaling the hardware is the right thing to do, not silly micro-optimization such as dealing with symlinks. Symbolic links provide you a clean and convenient way to switch between web site version etc; use them happily.

1
  • thanks for the great response Janne! Your response is (IMO) equally as good as Joel's response. However, Joel's response was both earlier, and referenced a great blog post. I will be accepting his response as a result. Thanks!
    – chadl
    Mar 15, 2012 at 18:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .