title: PHP readdir, glob and exec('ls') return in an empty array for some directories under Apache
body: <p>I have developed the following PHP code in order to read a specific directory called <code>/dados/capture</code>:</p>
  
  <p><code>tst2.php</code></p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;?php
  echo "whoami: " . shell_exec('whoami')."&lt;br&gt;\n";
  exec('ls /dados/capture/',$base);
  echo "/dados/capture content ...&lt;br&gt;\n";
  foreach ( $base as $dir )
  {
      print $dir ."&lt;br&gt;\n";
  }
  ?&gt;
  </code></pre>
  
  <p>Executing the code through linux command line "[root$mysite]# sudo -u apache php tst2.php" returns the following:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  whoami: apache
  &lt;br&gt;
  /dados/capture content ...&lt;br&gt;
  120130312115149.jpg&lt;br&gt;
  120130312115149.swf&lt;br&gt;
  120130312115658.jpg&lt;br&gt;
  120130312115658.swf&lt;br&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Calling <code>tst2.php</code> from web browser results in:</p>
  
  <pre><code>whoami: apache 
  /dados/capture content ...
  </code></pre>
  
  <p>I have tried changing the permission for the folder(s) and creating directive <code>&lt;directory&gt;&lt;directory&gt;</code> in <code>httpd.conf</code>, without any change to the result.</p>
  
  <p>I have tested the code with different directory it was a surprise, because it also doesn't work for <code>/boot</code>, <code>/mnt</code> and <code>/opt</code> directories.</p>
  
  <p>Using <code>glob</code> or <code>readdir</code> result the same, but consumes much more processor.</p>
  
  <p>I'm using CentOs 2.6.32-279.22.1.el6.i686, Apache/2.2.15 and PHP 5.4.12.</p>
  
  <p>Did someone have a similar problem?</p>