PHP SoapClient 将响应写入文件
这是我第一次使用 SOAP(但我的 PHP 相当不错)。我的问题是,我连接到一个服务器,该服务器通过soap向我发送大型xml(大到大于50mb),并且我不知道PHP的SoapClient使用什么来解析xml,但我担心它可能会使我的脚本耗尽记忆。
我可以将 SOAP 响应写入文件,这样就不会使用太多内存吗?或者说这甚至是一种威胁?
通常我会将响应写入文件,然后使用 XMLReader 读取它,但现在我只是解析响应。
$client = new SoapClient("http://....wsdl",array(
'login' => 'test',
'password' => 'test'));
$something = $client->__soapCall('getThings',array());
var_dump($something);
die();
It's the first time I'm using SOAP (but I'm pretty good in PHP). My problem is that I connect to a server that sends me large xmls through soap (large as in bigger than 50mb) and I don't know what PHP's SoapClient uses to parse xml but I'm afraid it might make my script run out of memory.
Could I write the SOAP response to file so I don't end up using too much memory? Or is that even a threat?
Normally I would write the response to file and then read it with XMLReader but right now I just get the response parsed.
$client = new SoapClient("http://....wsdl",array(
'login' => 'test',
'password' => 'test'));
$something = $client->__soapCall('getThings',array());
var_dump($something);
die();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
恐怕在您将其写入单独的文件之前,它已经占用了内存上的一些空间,更糟糕的是,它会执行大量进程并占用内存上更多的空间,我认为另一种好方法是寻找您使用的函数上的参数可以控制响应的大小,例如对于每个响应,我只想有最大 5mb 的响应大小。我发现解释起来有点困难,但这是您可以使用分页概念做的事情,您将每个页面限制为 5 个项目,例如在第 1 页上显示 5 个项目,在第 2 页上显示另外 5 个项目,依此类推。如果这不起作用或者不可能这样做,那么最后一个选择是升级您的服务器以能够支持您真正需要的东西我知道这可能是一个更重的选择,但如果没有其他方法那么我认为这会是解决您问题的最可行的选择。 :)
I'm afraid that before you could write it on a separate file it's already occupying some space on your memory and the worse it would do a lot of process and occupy more space on the memory instead, I think another good approach is to look for a parameter on the function your using that could control the size of the response like for each response I want only to have a maximum of 5mb response size. I find it a bit difficult to explain but it's something you would do with pagination concepts you limit each page to 5 items for example on page 1 display 5 items, on page 2 another 5 items and so on. If that wouldn't work or it's not possible to do so then the last option is upgrade your server to be able to support what you really need I know this might be a heavier option but if there is no other way then I think this would be the most feasible option to resolve you problem. :)