title: 502 error due to PHP crashes with signal 6 (SIGABRT) or 11 (SIGSEGV)
body: <p>I've seen a lot of posts that others get 502 error due to PHP crashes with signal 6 (SIGABRT) or 11 (SIGSEGV) but unfortunately none of the provided solution fixes mine. I'm in the process to get the back trace of the core dump and also using Valgrind Memcheck but in the meantime, I just want to post here to see if any of you have any hint or procedure to debug this.</p>
  
  <p>Here's what happen: various scripts crash at kind of random places but most of time <em>after</em> the main script exits/returns (with no error), i.e., the class destructor/shutdown methods get called and the last line in the main script gets executed.</p>
  
  <ul>
  <li><strong>Nginx</strong> error:
  2015/06/23 03:57:37 [error] 10930#0: *318186 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 68.71.252.49, server: , request: "POST /rest/user-logout.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "xyz"</li>
  <li><strong>php-fpm</strong> error:
  [18-Jun-2015 04:14:51] WARNING: [pool www] child 22018 exited on signal 6 (SIGABRT) after 548.942578 seconds from start</li>
  </ul>
  
  <p><strong>IMPORTANT NOTES</strong>: </p>
  
  <ul>
  <li>The servers are <em>not</em> under high load (never get "server reached pm.max_children setting").</li>
  <li>Reduce pm.max_requests to low number reduces the frequency of crashes</li>
  </ul>
  
  <p>php-fpm statuses seem normal. I've tried all the settings combination so I won't post them here but I'll post whatever you need to know. </p>
  
  <p>Here's the example code snippet to understand the constructs and usages:</p>
  
  <pre><code>class Job {
    function execute() {
      // The following code are in separate classes but listed here for easier to follow.
      $cache = new Memcached();
      $cache-&gt;addServer(...);
  
      $link = mysqli_init(...);
      mysqli_real_connect($link, ...);
  
      $res = $cache-&gt;get(...);
      if (!$res) {
        $res = mysqli_query($link, $sql);
      }
      // Process the result.
    }
  }
  $job = new Job();
  $job-&gt;execute();
  // Most of the time, it crashes after the last line (i.e. after invoking destructor/shutdown hook).
  </code></pre>
  
  <ul>
  <li>Nginx => 1.6.2</li>
  <li>PHP/php-fpm Version => 5.3.19 </li>
  <li>libcouchbase version => 2.5.0 </li>
  <li>memcached Version => 2.1.0 </li>
  <li>MySQL Client API version => 5.5.28</li>
  </ul>
  
  <p>-Frank</p>
  
  <p>P.S. I'll post these questions in separate topics: What exactly happen after the script exits/returns (besides saving the session)? In other words, what does php-fpm do to the process when it gets returned to the pool (e.g. class states, static variables)? I either close database connections explicitly or they will be closed automatically.</p>