title: Salesforce/PHP - Bulk Outbound message (SOAP), Time out issue - See update #2
body: <p>Salesforce can send up to 100 requests inside 1 SOAP message. While sending this type of Bulk Ooutbound message request my PHP script finishes executing but SF fails to accept the ACK used to clear the message queue on the Salesforce side of things. Looking at the Outbound message log (monitoring) I see all the messages in a pending state with the Delivery Failure Reason "java.net.SocketTimeoutException: Read timed out". If my script has finished execution, why do I get this error? </p>
  
  <p>I have tried these methods to increase the execution time on my server as I have no access on the Salesforce side:</p>
  
  <ul>
  <li>set_time_limit(0); // in the script</li>
  <li>max_execution_time = 360     ; Maximum execution time of each script, in seconds</li>
  <li>max_input_time = 360    ; Maximum amount of time each script may spend parsing request data</li>
  <li>memory_limit = 32M      ; Maximum amount of memory a script may consume</li>
  </ul>
  
  <p>I used the high settings just for testing.</p>
  
  <p>Any thoughts as to why this is failing the ACK delivery back to Salesforce?</p>
  
  <p>Here is some of the code:
  This is how I accept and send the ACK file for the imcoming SOAP request</p>
  
  <pre><code>$data = 'php://input';
  $content = file_get_contents($data);
  
  if($content) {
      respond('true');
  } else {
      respond('false');
  }
  </code></pre>
  
  <p>The respond function</p>
  
  <pre><code>function respond($tf) {
      $ACK = &lt;&lt;&lt;ACK
  &lt;?xml version = "1.0" encoding = "utf-8"?&gt;
  &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;soapenv:Body&gt;
          &lt;notifications xmlns="http://soap.sforce.com/2005/09/outbound"&gt;
              &lt;Ack&gt;$tf&lt;/Ack&gt;
          &lt;/notifications&gt;
      &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  ACK;
  
      print trim($ACK); 
  }
  </code></pre>
  
  <p>These are in a generic script that I include into the script that uses the data for a specific workflow. I can process about 25 requests (That are in 1 SOAP response) but once I go over that I get the timeout error in the Salesforce queue. for 50 requests is usually takes my PHP script 86.77 seconds.</p>
  
  <p>Could it be Apache? PHP? </p>
  
  <p>I have also tested just accepting the 100 request SOAP response and just accepting and sending the ACK the queue clears out, so I know it's on my side of things.</p>
  
  <p>I show no errors in the apache log, the script runs fine.</p>
  
  <p>I did find some info on the Salesforce site but still no luck. Here is <a href="http://www.salesforce.com/us/developer/docs/api/apex_api.pdf" rel="nofollow noreferrer">the link</a>.</p>
  
  <p>Also I'm using the PHP Toolkit 11 (From Salesforce).</p>
  
  <p><a href="http://www.mikesimonds.com/salesforce-php-bulk-outbound-message-soap-time-out-issue-t223.html#post1034" rel="nofollow noreferrer">Other forum with good SF help</a></p>
  
  <p>Thanks for any insight into this,
  --Phill</p>
  
  <p>UPDATE:</p>
  
  <p>If I receive the incoming message and print the response, should this happen first regardless if I do anything else after? Or does it wait for my process to finish and then print the response? </p>
  
  <p>UPDATE #2:</p>
  
  <p>okay I think I have the problem:
  PHP uses the single thread processing approach and will not send back the ACK file until the thread has completed it's processing. Is there a way to make this a mutli thread process?
  Thread #1 - accept the incoming SOAP request and send back the ACK
  Thread #2 - Process the SOAP request</p>
  
  <p>I know I could break it up into like a DB table or flat file, but is there a way to accomplish this without doing that?</p>
  
  <p>I'm going to try to close the socket after the ACK submission and continue the processing, cross my fingers it will work.</p>