PHP从Soap响应中保存XML,即使它因超时而失败

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 

?>
duanju8308
duanju8308 我尝试将XML直接加载到DOMDocument中,但它遇到了错误,但这样做却没有。我不记得exat错误代码,我对该服务有2小时的请求时间限制,所以我真的不想检查错误代码是什么。
大约 6 年之前 回复
doujianjian2060
doujianjian2060 你需要同时使用simplexml和DOMDocument吗?您可以使用loadXML将XML直接加载到DOMDocument中,并绕过$xml=simplexml_load_string($xmlsoap);步。
大约 6 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐