PHP SOAP fread() 动态 POST 大小
希望读取 SOAP POST 的文件大小,有什么最佳实践吗?
$data = fopen('php://input','rb');
$content = fread($data,5000);
$dom = new DOMDocument();
$dom->loadXML($content);
是否希望 5000 是动态的,因为每个 SOAP POST 大小都会不同,或者这很重要吗?
使用 fread() 会很棒
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);
Would like the 5000 to be dynamic as each SOAP POST size will be different or does this matter?
Using fread() would be great
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯。如果您可以使用“
fread
”读取它,我认为您没有理由不能使用“file_get_contents()
”读取完全相同的文本。我用过几次,记得我都尝试过。就“
fread
”的最佳实践而言,您需要的是可以从 getallheaders() 获取的文件大小。因此,如果您仍然喜欢使用“
fread
”,这里是代码。上面的代码是自我解释的,因此不需要进一步解释。请注意,如果长度 长于 8192 字节内容将被剪辑。所以你最好检查一下读取长度,看看它是否被剪裁。 (不过,如果您使用“
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.As far as the best practice for '
fread
' goes, what you need is the file size which you can get it from getallheaders().So, if you still prefer using '
fread
' here is the code.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).Hope this helps
您可以尝试以下操作:
这将获取所有内容,无论数据的长度如何。
You could try the following instead:
This will get all contents, no matter the length of the data.