How to avoid "ls: write error: Broken pipe" with php exec
<p>I'm having an error that causes me a very big waste of time. This is the line:</p>

<pre><code> exec ("ls -U ".$folder." |head -1000", $ls_u);
</code></pre>

<p>This command runned on my shell needs less than a second, launched by php (direct from console, not throw apache) needs more than 15 seconds and I get this error:</p>

<p>ls: write error: Broken pipe</p>

<p>In the directory where is performing this action has more than 4.5M files, for this reason I use ls -U | head -1000 of course if the | fails it needs to list 4.5M files, besides than do just 1K.</p>

<p>Where is the error? Or using pipes in php exec is not a good idea?!</p>

<p>Thanks</p>
