2009/12/01

php soap wget curl

php.ini has the following pertinent settings:

default_socket_timeout = 120
max_execution_time = 60
memory_limit = 20M

In soap client, connection_timeout is equivalent to default_socket_timeout.

<?php

$soapClient = new SoapClient('http://www.example.com/path/to.wsdl',
array('connection_timeout' => 120));

?>

Looks like soapclient use similar technique as file_get_contents() does
to get wsdl file. But unlike wget, file_get_contents generates distinct
packet for each line of HTTP request. Server doesn't reply on these
small chunks.

To let PHP behave like wget:

Define the following function:

function curl_file_get_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);

if ($contents) return $contents;
else return FALSE;
}

And replace all file_get_contents entries with curl_file_get_contents.