とを使用SplFileObject
しLimitIterator
て、大きなファイルの位置xからyまでのコンテンツを読み取ります。
これは、のようなファイルパスを使用する場合に完全に機能します/home/devel/stuff/myfile.log
。
そのようなパスを使用するhttp://mydomain.com:8090/devel/stuff/myfile.log
と機能しません。ただし、パスは正しいです。
絶対パスを使用するとこれは失敗しますか?
エラーメッセージは次のとおりです。
PHP Warning: SplFileObject::rewind() [<a href='splfileobject.rewind'>splfileobject.rewind</a>]: stream does not support seeking in ...
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Cannot rewind file ...'
完全なコード:
// $pStrFile contains the valid (yes!) path
$oFile = new SplFileObject($pStrFile);
// $nFrom = 80 and $nLines = 30
$fileIterator = new LimitIterator($oFile, $nFrom, $nLines);
foreach($fileIterator as $line) {
$strLines .= $line;
}