Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 01-18-2012, 11:24 AM   #1
LQ Newbie
Registered: Jan 2012
Posts: 7

Rep: Reputation: Disabled
PHP shell_exec() always gives error "Broken pipe" when using pipe

Hi all.

I have an error im my apache's error.log saying:
/bin/grep: writing output: Broken pipe
I've traced the source of the problem to this line:
shell_exec("/bin/netstat -e -p --tcp -n 2> /dev/null | /bin/grep -v root | /bin/grep -v | /bin/grep -cE '.*(python|transmissionc|wget|nzbperl|java).*'");

I replaced (just for test) the upper line with:
shell_exec("ls | ls | ls | ls");
and now I get:
ls: write error: Broken pipe
My conclusion was that something is wrong with PHP handling pipes or some linux's security feature is preventing php script to execute that pipe, because when I try the same from shell, I don't get such errors.
I've tried with su -c "ls | ls | ls | ls" www-data and also with su - www-data followed with ls | ls | ls | ls without errors.

I also get the same error if I make a test.php file containing just:
shell_exec('ls | ls | ls | ls');
and running it with php -f test.php 2>&1, gave me the same error:
# php -f test.php 2>&1
ls: write error: Broken pipe
(I even tried with just ls | ls and it gave out the same error but not always (1 out of 6 tries).

Can you please just shoot out any idea that first gets to your mind of what the problem could actually be?

I have torrentflux-b4rt installed on my debian machine (stable, squeeze 6.0.3, "Linux ninja 2.6.26-2-amd64 #1 SMP Wed Sep 21 03:36:44 UTC 2011 x86_64 GNU/Linux") with apache web server (apache2 2.2.16-6+squeeze4) and php5 (libapache2-mod-php5 5.3.3-7+squeeze3) installed.

I'm not sure if I've chosen the correct forum, but I hope mods will point this out to me if I'm wrong.
Old 01-19-2012, 07:04 AM   #2
LQ Newbie
Registered: Jan 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
I've solved this issue. It had to do something with ulimit command.
Even though I had uncommented line "session required" in /etc/pam.d/login and I had put
* hard nofile 102400
* soft nofile 102400
* hard nproc  102400
* soft nproc  102400

www-data soft nproc 10240
www-data hard nproc 40960
in /etc/security/limits.conf
it still didn't want to create more than 20 apache processes (required by torrentflux)
I've restarted apache2 numerous times and finally I managed to solve this by adding:
root soft nproc 102400
root hard nproc 102400
in /etc/security/limits.conf
and also changing apache config file /etc/apache2/apache2.conf by modifying this section:
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers     100
    MaxClients          150
    MaxRequestsPerChild   0
( MaxSpareServers was 10 and I've changed it to 100 )
After the restart of apache with /etc/init.d/apache2 restart, everything worked great (so far)
Hope this helps someone in the future


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
/dev/ttyUSB0 + "broken pipe": how to force re-discovery? kaza Linux - Hardware 2 12-09-2011 03:13 PM
bash scripting sending "cat: write error: Broken pipe," rojoblandino Linux - Server 8 04-23-2010 11:23 AM
Finding the latest file - "broken pipe" error RasmusThomsen Linux - Server 3 11-30-2009 05:04 PM
"broken pipe" in installing Ndiswrapper joshknape Linux - Newbie 0 02-15-2006 12:27 AM
ifconfig usb0 produces "Broken pipe" JohnKFT Slackware 0 11-13-2004 05:56 PM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration