Simlink real-world example

I read php functions and I came across symlink , but I really couldnโ€™t capture it, especially its use in real-world application development. Can someone explain to me the real world example?

thanks

+6
php
source share
5 answers

Suppose you have an src folder in the $HOME directory where your sources are stored. When you open a new shell, you usually enter your $HOME directory when the shell starts. This can be a general step, whenever whenever you open a new shell, you want to subsequently enter the ~/src/very_long_project_name .

Symbolic links appear here: you can create a symbolic link in your $HOME directory (for example, called vlpn , which directly points to ~/src/very_long_project_name .

The next time you open the console, you can simply type cd vlpn instead of cd src/very_long_project_name . It. Nothing special about PHP. Like giraff and gnur already said.

+4
source share

The administrator can create symbolic links to organize storage without corrupting file systems; for example, a web mirror can contain thousands of hosted sites, and dozens of drives are installed:

 /mnt/disk1/ /mnt/disk2/ ... 

and you want to store data in your /var/www/htdocs/ without worrying about which drive stores their data.

 /var/www/htdocs/debian -> /mnt/disk1/debian /var/www/htdocs/ubuntu -> /mnt/disk2/ubuntu /var/www/htdocs/centos -> /mnt/disk9/centos 

Secondly, you may have a "last boot"; your users upload photos or software packages, and you want http://example.com/HOT_STUFF always be the most recent photo uploaded. You can set symlink($new_upload, $HOT_STUFF); , and users donโ€™t need more than one URL to see the newest thing.

Thirdly, Debian and Ubuntu use the update-alternatives mechanism to immediately install several versions of the tool and still allow the administrator to specify which one is the default. eg.

 $ ls -l /usr/bin/vi lrwxrwxrwx 1 root root 20 2011-01-11 01:07 /usr/bin/vi -> /etc/alternatives/vi $ ls -l /etc/alternatives/vi lrwxrwxrwx 1 root root 18 2011-01-11 01:07 /etc/alternatives/vi -> /usr/bin/vim.basic $ ls -l /usr/bin/vim.basic -rwxr-xr-x 1 root root 1866904 2010-09-28 04:06 /usr/bin/vim.basic 

This is a bit cool, but the configuration is saved in the directory for each system /etc/ , and the usual path /usr/bin/vi will do what is very similar to vi when there are many options available (nvi, elvis, vim, AT & T vi etc.)

+3
source share

Symbols are what is used on the host OS, and not just on PHP itself.
It creates a shortcut for the file. It may be useful to request a much-used file with a long path by creating a symbolic link in the public_html folder to a long path that you can include in it without using the full path.

http://en.wikipedia.org/wiki/Symbolic_link

//edit:
This is better than just copying the file, because you are really using the original file, so if the original change of the symbolic link always points to a new file, then this is not a copy!

+1
source share

The php function actually delegates only the functionality of the operating system, which is why it is as useful as a symbolic symlink in general:

Symbolic links work transparently for most operations: programs that read or write files, a symbolic link will behave as if directly working with the target file.

(from Wikipedia)

I saw how it was used by Typo3 :

On each Typo3 site there is a folder that links to the main installation - therefore several sites can use the same code base, and Typo3 can be updated by extracting the new version and then changing the symbolic links (reducing the siteโ€™s offline life).

+1
source share
+1
source share

All Articles