title: Heavy load because of concurrent users causes 502 bad gateway error
body: <p>I have Nginx + PHP FPM installed on my server. We are putting load on server for long period for 30 concurrent users.</p>
  
  <p>For initial user it works fine but after some time it starts throwing 502 bad gateway error.</p>
  
  <p>I have placed some of the log of nginx php-fpm and slow log of php-fpm.</p>
  
  <p>There are entries getting logged in slow log of php-fpm because of long running script and load on server. I think this is the reason for 502 bad gateway error. But I dont know how to solve that problem.</p>
  
  <ul>
  <li>What are the tweaks I need to make in php-fpm.conf so that this errors gets resolved?</li>
  <li>How to make nginx wait for long time for response from php-fpm?</li>
  <li>How to increase php-fpm max execution time?</li>
  </ul>
  
  <p>Here are the logs attached.</p>
  
  <h3>NGINX LOG</h3>
  
  <blockquote>
    <p>2013/01/29 15:03:38 [error] 2493#0: <em>1046562 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 49.248.0.2, server: <strong></em>**<em>*</em>*</strong>.com, request: "GET MY_SCRIPT_URI HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "<strong><em>*</em>****</strong>.com", referrer: "MY_SCRIPT_URL"</p>
    
    <p>2013/01/29 15:03:39 [error] 2493#0: <em>1046561 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 49.248.0.2, server: <strong></em>**<em>*</em></strong>.com, request: "GET MY_SCRIPT_URI HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "<strong><em>*</em>****</strong>.com", referrer: "MY_SCRIPT_URL"</p>
  </blockquote>
  
  <p>There are many errors of this type and they are repeating in entire file.</p>
  
  <h3>PHP FPM LOG</h3>
  
  <pre><code>[14-Feb-2013 12:54:13] ERROR: failed to ptrace(PEEKDATA) pid 10748: Input/output error (5)
  [14-Feb-2013 12:54:18] ERROR: failed to ptrace(PEEKDATA) pid 10112: Input/output error (5)
  [14-Feb-2013 12:54:18] ERROR: failed to ptrace(PEEKDATA) pid 12147: Input/output error (5)
  [14-Feb-2013 12:54:19] ERROR: failed to ptrace(PEEKDATA) pid 30857: Input/output error (5)
  [snip: many more]
  </code></pre>
  
  <h3>PHP FPM SLOW LOG</h3>
  
  <blockquote>
    <p>[14-Feb-2013 12:55:13] [pool www] pid 10748
    script_filename = MY_SCRIPT_PATH
    [0x00007f446e8e06b0] curl_exec() MY_SCRIPT_PATH_1.php:317
    [0x00007f446e8e0490] callService() MY_SCRIPT_PATH_2:1331
    [0x00007f446e8e0148] convertToPurchaseOrders() MY_SCRIPT_PATH_3:15
    [0x00007fff0102b4d0] convertToPurchaseOrders() unknown:0
    [0x00007f446e8de0d8] call_user_func_array() MY_SCRIPT_PATH_4:359
    [0x00007f446e8dd4d0] +++ dump failed</p>
    
    <p>[14-Feb-2013 12:55:13] [pool www] pid 10117
    script_filename = MY_SCRIPT_PATH
    [0x00007f446e8e06b0] curl_exec() MY_SCRIPT_PATH_1.php:317
    [0x00007f446e8e0490] callService() MY_SCRIPT_PATH_2:1331
    [0x00007f446e8e0148] convert() MY_SCRIPT_PATH_3:15
    [0x00007fff0102b4d0] convert() unknown:0
    [0x00007f446e8de0d8] call_user_func_array() MY_SCRIPT_PATH_4:359
    [0x00007f446e8dd4d0] +++ dump failed</p>
  </blockquote>