file_get_contents(): stream does not support seeking / When was PHP behavior about this changed?

后端 未结 7 1642
醉酒成梦
醉酒成梦 2020-12-06 05:00

When was PHP behavior about this changed?

From which PHP version is it?


Warning: file_get_contents(): stream does not supp

7条回答
  •  暖寄归人
    2020-12-06 05:42

    Others have shared the solution, but no one has shared why. I don't know specifically why this is different between PHP 7.0 & 7.1, but the PHP.net docs for this function say:

    Seeking (offset) is not supported with remote files. Attempting to seek on non-local files may work with small offsets, but this is unpredictable because it works on the buffered stream.

    I can confirm that removing the offset parameter in file_get_contents on line 75 works for me and/or setting the offset to 0 in the file_get_html function on line 70 works too.

    I guess that the offset parameter was never meant to be used with non local files since:

    The offset where the reading starts on the original stream. Negative offsets count from the end of the stream.

    Hope this helps clear up any confusion. With external sources, it makes sense to start streaming from the beginning.

提交回复
热议问题