PHP SOAP fread()动态POST大小 [英] PHP SOAP fread() dynamic POST size

查看:86
本文介绍了PHP SOAP fread()动态POST大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要读取SOAP POST的文件大小,是否有最佳实践?

Looking to read the file size of the SOAP POST, any best practices?

$data = fopen('php://input','rb');
$content = fread($data,5000);

$dom = new DOMDocument();
$dom->loadXML($content);

由于每个SOAP POST的大小会有所不同,还是希望5000是动态的?

Would like the 5000 to be dynamic as each SOAP POST size will be different or does this matter?

使用fread()会很棒

Using fread() would be great

推荐答案

嗯.如果您可以使用'fread'进行阅读,那么我看不出没有任何理由无法阅读与'file_get_contents()'完全相同的文本.我使用了几次,并记住我已经尝试过两次.

Umm. If you can read it with 'fread', I see no reason you cannot read EXACT same text with 'file_get_contents()'. I use this a few times and remembering that I've try both.

就"fread"的最佳做法而言,您需要的是可以从getallheaders()获取的文件大小.

As far as the best practice for 'fread' goes, what you need is the file size which you can get it from getallheaders().

因此,如果您仍然喜欢使用'fread',则这里是代码.

So, if you still prefer using 'fread' here is the code.

$data = fopen('php://input','rb');
$Headers = getallheaders();
$CLength  = $Headers['Content-Length'];
$content = fread($data,$CLength);

$dom = new DOMDocument();
$dom->loadXML($content);

上面的代码是自我解释的,因此无需进一步解释.请注意,如果长度为大于8192字节内容将被剪切.因此,您最好检查读取的长度以查看是否被剪切. (不过,如果您使用'file_get_contents()',则不必担心.)

The code above is self explained so there is no need for further explanation. Just a little bit note that if the length is longer than 8192 bytes the content will be clipped. So you better check the read length to see if it clipped. (You will not need to be worry if you use 'file_get_contents()' though).

希望这会有所帮助

这篇关于PHP SOAP fread()动态POST大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆