The Linux Page

PHP glob function does not return softlinks

I use all sorts of tricks in order to duplicate functionality without actually duplicating PHP code.

One of the main, easiest way under Unix is to create softlinks. First put all your code in one folder, then create a softlink to it. That gives you two paths:

  myfolder

  mysoftlink -> myfolder

Thus, when you run your PHP code, you get either myfolder or mysoftlink in your URL. You can then write the PHP code to detect that name and act on it (i.e. if that's the name of a user, then it will send you to the specific user profile.)

In order to get a list of these links, I used the glob() function on the folder. Say you have your data in /var/www-data/public_html/myapp then you would write this:

  $array = glob('/var/www-data/public_html/myapp/*');

That was giving me the complete list. Then I would test for myfolder and skip it since it is not a user. The rest would be my list of users.

This worked great on Fiesty. However, on Ubuntu 8.10 (Intrepid), it breaks. I have no clue why at this time, but the glob() function only returns myfolder. All the softlinks are ignored.

It feels like the system checks and notices that the softlinks point to the same folder and thus ends up no listing them. The other possibility is that they decided to not list softlinks by default. Usually there is a setup for these sort of things and I could not find anything about that either. In any event, the result is that it won't do anything unless we fix our code! So I now use an opendir(), readdir() and closedir() instead. That works just fine and is easy to use.