views:

324

answers:

1

I've been debugging some Soap requests we are making between two servers on the same VLAN. The app on one server is written in PHP, the app on the other is written in Java. I can control and make changes to the PHP code, but I can't affect the Java server. The PHP app forms the XML using the DOMDocument objects, then sends the request using the cURL extension.

When the soap request took longer than 5 minutes to complete, it would always wait until the max timeout limit and exit with a message like this:

Operation timed out after 900000 milliseconds with 0 bytes received

After sniffing the packets that were being sent, it turns out that the problem was caused by a 5 minute timeout in the network that was closing what it thought was a stale connection. There were two ways to fix it: bump up the timeout in iptables, or start sending KeepAlive packets over the request.

To be thorough, I would like to implement both solutions. Bumping up the timeout was easy for ops to do, but sending KeepAlive packets is turning out to be difficult. The cURL library itself supports this (see the --keepalive-time flag for the CLI app), but it doesn't appear that this has been implemented in the PHP cURL library. I even checked the source to make sure it wasn't an undocumented feature.

So my question is this: How the heck can I get these packets sent? I see a few clear options, but I don't like any of them:

  • Write a wrapper that will kick off the request by shell_execing the CLI app. This is a hack that I just don't like
  • Update the cURL extension to support this. This is a non-option according to Ops.
  • Open the socket myself. I know just enough to be dangerous. I also haven't seen a way to do this with fsockopen, but I could be missing something.
  • Switch to another library. What exists that supports this?

Thanks for any help you can offer.

A: 

You could try setting "Connection: Keep-Alive", as in:

curl_setopt($process, CURLOPT_HTTPHEADER, array('Connection: Keep-Alive'));

Or you might also putting the curl call in an ajax script.

SOAP sends a LOT of data back and forth and I don't know of any PHP library to date that is light-weight and efficient at either formatting or parsing SOAP XML. I ran into a similar problem when communicating with a .NET server using PHP and (you won't like this hack either) it was so slow that I eventually stopped using SOAP; instead, I just posted the data via curl and parsed only portions of the response that I needed using SimpleXml.

bogeymin
HTTP Keep-Alive headers are unrelated to TCP/IP keepalives.
EricLaw -MSFT-