gpt4 book ai didi

php - fread 读取不超过 8192 字节

转载 作者:行者123 更新时间:2023-12-01 23:51:01 25 4
gpt4 key购买 nike

我遇到一个奇怪的问题,即 fread 拒绝读取超过 8192 字节。我知道这是读取缓冲的远程流的预期行为,但这是由 PHP 脚本创建的本地 .zip 文件。

代码示例:

$fh = fopen('/path/to/file.zip', 'rb');
$data = fread($fh, 4194304); // 4 MB
echo strlen($data);

输出:8192

文件本身大小为 9 mb。

如果我在 CLI 中运行它,它工作得很好。

PHP 版本为 7.1。

知道为什么我会遇到这个问题吗?

最佳答案

根据docs这就是它的作用:

if the stream is read buffered and it does not represent a plain file, at most one read of up to a number of bytes equal to the chunk size (usually 8192) is made; depending on the previously buffered data, the size of the returned data may be larger than the chunk size.

关于php - fread 读取不超过 8192 字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49302836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com