LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 01-18-2012, 10:24 AM   #1
burek
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:
Code:
/bin/grep: writing output: Broken pipe
I've traced the source of the problem to this line:
Code:
shell_exec("/bin/netstat -e -p --tcp -n 2> /dev/null | /bin/grep -v root | /bin/grep -v 127.0.0.1 | /bin/grep -cE '.*(python|transmissionc|wget|nzbperl|java).*'");

I replaced (just for test) the upper line with:
Code:
shell_exec("ls | ls | ls | ls");
and now I get:
Code:
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:
Code:
<?
shell_exec('ls | ls | ls | ls');
and running it with php -f test.php 2>&1, gave me the same error:
Code:
# 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, 06:04 AM   #2
burek
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 pam_limits.so" in /etc/pam.d/login and I had put
Code:
* 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:
Code:
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:
Code:
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers     100
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>
( 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
 
  


Reply


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 02:13 PM
bash scripting sending "cat: write error: Broken pipe," rojoblandino Linux - Server 8 04-23-2010 10:23 AM
Finding the latest file - "broken pipe" error RasmusThomsen Linux - Server 3 11-30-2009 04:04 PM
"broken pipe" in installing Ndiswrapper joshknape Linux - Newbie 0 02-14-2006 11:27 PM
ifconfig usb0 produces "Broken pipe" JohnKFT Slackware 0 11-13-2004 04:56 PM


All times are GMT -5. The time now is 01:35 AM.

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