I would like to save a SOAP response to an XML file but even with memory limit set to 500M and timeout to 900 it fails with to many request error. According to the manual for that soap service they recommend increasing the memory and time limit to avoid this but I think 500M/900 is pretty high already.
I saw that my script is creating the file and until the point where it fails it writes the data into that file(which was about 52MB that time) but when the request fails the data in the file is overwritten by error message.
Is there any way to keep that data which is already written out correctly to the file even if the request fails?
I save the XML like this:
<?php
ini_set('memory_limit', '500M');
ini_set('max_execution_time','900');
ini_set('default_socket_timeout','900');
$pid='39';
$auth = 'ABCD1234-EFGH5678';
$client = new SoapClient('http://www.example.com/services/service.asmx?WSDL',
array("trace" => 1,"exceptions" => 0,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS));
$result=$client->GetStuff(array('pid'=>$pid, 'authcode'=>$auth));
$xmlsoap = $result->GetStuffResult->any;
$xml = simplexml_load_string($xmlsoap);
$doc = new DOMDocument();
$doc->formatOutput = TRUE;
$doc->loadXML($xml->asXML());
$newxml = $doc->saveXML();
$outputFilename = 'output'.date('Ymd').'.xml';
$handle = fopen($outputFilename, "w");
fwrite($handle, $newxml);
fclose($handle);
echo 'ready'; //this echo is here only for testing purposes
?>