dongyi2534 2014-10-15 23:05
浏览 37

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 

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器