Why does PHPs glob() fail for /var/* ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
js2007
Forum Newbie
Posts: 8
Joined: Thu Oct 09, 2008 9:37 am

Why does PHPs glob() fail for /var/* ?

Post by js2007 »

Hi

glob('/var/*') and glob('/var/www/*') all return empty arrays for any subdir.

I tried it with PHP 5.2.0 and 5.2.6 on the same machine. System is Debian Sarge.

/var is a mounted ReiserFS partition, could this be a cause?

Other glob() calls work:

glob('/*') -> lists all dirs in the root, even /var
glob('/usr/*') -> lists all files / dirs within /usr
glob('/var*') -> returns the single entry '/var'

/var is not empty and permissions are 755.
I can fopen, include etc any file within /var, /var/www is the document_root.

There are only a few files and dirs in /var so it can't be because of the known bug that many files cause a segfault in glob.

Thanks in advance,
JS
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Why does PHPs glob() fail for /var/* ?

Post by VladSun »

There is a really big difference between /var* and /var/*
There are 10 types of people in this world, those who understand binary and those who don't
js2007
Forum Newbie
Posts: 8
Joined: Thu Oct 09, 2008 9:37 am

Re: Why does PHPs glob() fail for /var/* ?

Post by js2007 »

Haha, i guess so. :D

the first one works and shows the correct entry in the system root
second one doesn't work so i guess he can't read inside that directory, but that only affects glob() so it's either a glob issue with the filesystem issue or a with the os (debian).
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Why does PHPs glob() fail for /var/* ?

Post by VladSun »

Sorry, but I can't reproduce your problem ...
Using glob('/var/*') gives the expexted result on my PC.
There are 10 types of people in this world, those who understand binary and those who don't
js2007
Forum Newbie
Posts: 8
Joined: Thu Oct 09, 2008 9:37 am

Re: Why does PHPs glob() fail for /var/* ?

Post by js2007 »

Thank you for trying, which filesystem is your /var folder on?

Regards, JS
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Why does PHPs glob() fail for /var/* ?

Post by VladSun »

ReiserFS
There are 10 types of people in this world, those who understand binary and those who don't
js2007
Forum Newbie
Posts: 8
Joined: Thu Oct 09, 2008 9:37 am

Re: Why does PHPs glob() fail for /var/* ?

Post by js2007 »

Wow, that's interesting. So it's not because of the fs but another problem, maybe special to my system.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Why does PHPs glob() fail for /var/* ?

Post by VladSun »

Whats the output of

Code: Select all

ls -l /var
ls -l /var/*
Also, post your code.

PS: Try to login as your Apache user and execute the commands above again.
There are 10 types of people in this world, those who understand binary and those who don't
js2007
Forum Newbie
Posts: 8
Joined: Thu Oct 09, 2008 9:37 am

Re: Why does PHPs glob() fail for /var/* ?

Post by js2007 »

My code:

Code: Select all

<?php
require_once "Var_Dump.php";
Var_Dump::display(glob('/var'));
Var_Dump::display(glob('/var/*'));
?>
 
this outputs:
array(1) {
0 => string(4) /var
}

array(0)
Output of the interesting line of 'ls -l /':

Code: Select all

drwxr-xr-x 17 root root    408 2008-10-09 14:15 var
 

Code: Select all

jake@dresden:~$ ls -l /var
total 9
drwxr-xr-x  2 root     root        864 2008-10-11 06:25 backups
drwxr-xr-x  8 root     root        192 2007-11-11 17:04 cache
drwxrwxr-x  9 jake     www-data    224 2008-09-30 17:44 data
drwxr-xr-x 30 root     root        768 2008-10-08 19:34 lib
drwxrwsr-x  2 root     staff        48 2006-12-20 11:03 local
drwxrwxrwt  3 root     root         96 2008-05-09 19:04 lock
drwxr-xr-x  8 root     root       3768 2008-10-11 06:26 log
drwxrwsr-x  2 root     mail         48 2007-10-15 16:08 mail
drwxr-xr-x  2 root     root         48 2006-12-20 11:03 opt
drwxr-xr-x 11 root     root        656 2008-10-11 04:47 run
drwxr-xr-x  7 root     root        192 2007-02-04 12:07 spool
drwxrwx---  4 root     subversion  112 2007-01-04 11:19 svn
-rw-r--r--  1 root     root          3 2008-10-09 14:15 tess
drwxrwxrwt  5 root     root        176 2008-10-08 19:12 tmp
drwxrwxr-x 10 www-data users       392 2008-10-09 12:51 www
 
ls -l /var/* looks the same but for the contents of each subdir of /var.

edit: If I execute this as www-data (apache user) it's completly the same.
Does this help?

Thank you,
JS
Post Reply