title: Resend PHP API request in case of failure (retry mechanism)
body: <p>My PHP script is working with multiple external services using API requests and theirs SDKs. It happens, that requests might fail and I would like to implement a retry mechanism.<br>
  SDKs don't have this feature built-in and they will just throw an <code>Exception</code> if request was not successful.<br>
  I've created multiple functions that use SDKs to retrieve / upload required data and now I would like to add retry mechanism if any of SDK requests fail. I could add a piece of code around every SDK call like this:  </p>
  
  <pre><code>$retry = 0;
  while ($retry &lt; 3) {
      try {
          $account = $client-&gt;load('account');
      } catch (\Exception $e) {
          $retry++;
      }
  }
  </code></pre>
  
  <p>But this means that I will add the same piece of code to every SDK function call and it's going to be a real mess.  </p>
  
  <p>Is there any possibility in PHP to create a generic function or some kind of wrapper that will retry executing function if it has failed (thrown an <code>Exception</code>)?</p>
  
  <p>P.S. SDKs use <code>curl</code> to send requests. Maybe, it's possible to tweak <code>curl</code> to implement this kind of retry mechanism?</p>