Salesforce/PHP - Bulk Outbound message (SOAP), Time out issue - See update #2

Posted by Phill Pafford on Stack Overflow See other posts from Stack Overflow or by Phill Pafford
Published on 2010-03-18T19:25:28Z Indexed on 2010/03/29 11:33 UTC
Read the original article Hit count: 736

Filed under:
|
|
|
|

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?

I have tried these methods to increase the execution time on my server as I have no access on the Salesforce side:

  • set_time_limit(0); // in the script
  • max_execution_time = 360 ; Maximum execution time of each script, in seconds
  • max_input_time = 360 ; Maximum amount of time each script may spend parsing request data
  • memory_limit = 32M ; Maximum amount of memory a script may consume

I used the high settings just for testing.

Any thoughts as to why this is failing the ACK delivery back to Salesforce?

Here is some of the code: This is how I accept and send the ACK file for the imcoming SOAP request

$data = 'php://input';
$content = file_get_contents($data);

if($content) {
    respond('true');
} else {
    respond('false');
}

The respond function

function respond($tf) {
    $ACK = <<<ACK
<?xml version = "1.0" encoding = "utf-8"?>
<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">
    <soapenv:Body>
        <notifications xmlns="http://soap.sforce.com/2005/09/outbound">
            <Ack>$tf</Ack>
        </notifications>
    </soapenv:Body>
</soapenv:Envelope>
ACK;

    print trim($ACK); 
}

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.

Could it be Apache? PHP?

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.

I show no errors in the apache log, the script runs fine.

I did find some info on the Salesforce site but still no luck. Here is the link.

Also I'm using the PHP Toolkit 11 (From Salesforce).

Other forum with good SF help

Thanks for any insight into this, --Phill

UPDATE:

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?

UPDATE #2:

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

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?

I'm going to try to close the socket after the ACK submission and continue the processing, cross my fingers it will work.

© Stack Overflow or respective owner

Related posts about php

Related posts about salesforce