title: PDO connection timed out in API, php-fpm restart solves it
body: <p>I keep getting the following error from my code:</p>
  
  <blockquote>
    <p>Database connect failed: PDO::__construct(): send of 12 bytes failed with errno=110 Connection timed out</p>
  </blockquote>
  
  <p>This error persistently happens on an api. If that api keeps getting called a lot during the day this does not happen. Only when the api is not used for some time.</p>
  
  <p>I can solve this by doing a php-fpm restart/reload, but this shouldn't be the solution.</p>
  
  <p>Does anybody have any idea how to solve this?</p>
  
  <p>--EDIT--</p>
  
  <p>This is the code for connection to the database:</p>
  
  <pre><code>public function connectDatabase($allow_persistent = true)
  {
      $this-&gt;db = null;
  
      $this-&gt;readINI();
  
      $pdo_attr = [
          PDO::ATTR_PERSISTENT =&gt; $allow_persistent,
          PDO::MYSQL_ATTR_INIT_COMMAND =&gt; "SET CHARACTER SET utf8;",
          PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true,
      ];
  
      $this-&gt;db = new PDO("mysql:host=" . $this-&gt;db_data_dbhost . ";dbname=" . $this-&gt;db_data_dbname . ";charset=utf8", $this-&gt;db_data_username, $this-&gt;db_data_password, $pdo_attr);
  
      $this-&gt;db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  }
  </code></pre>
  
  <p>To itterate some more, this is used on two API's at the moment. </p>
  
  <ul>
  <li>One is consistently used by customers and never encounters this problem</li>
  <li>The second is not used by a lot of customers yet seeing as this is still in development, it's only with a few customers for testing purposes. We do try to push an app to the appstore but it gets shot down by this problem. This API will eventually run into the error as depicted above and will not recover from this state without restarting/reloading the php-fpm service.</li>
  </ul>