[php-src] Issue #8182: The current() method of SplFileObject has a very low probability of not returning complete data
| From: | hisune | Date: | Tue, 08 Mar 2022 07:40:18 +0000 |
| Subject: | [php-src] Issue #8182: The current() method of SplFileObject has a very low probability of not returning complete data | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-240257@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8182
Author: hisune
### Description
I wrote a composer package that synchronizes log content to clickhouse in real time. After
verification of the online log, I found that there is a very low probability that the current()
method cannot return complete data.The code is in this file:
https://github.com/hisune/log2ck/blob/94ca81f600c1fef5919fc58ffd737ccd15dc7654/src/Worker.php#L73
The following code:
```php
<?php
$file = new SplFileObject($this->path);
$file->seek($this->getCurrentLines());
while($this->onProcess){
$line = $file->current();
if($file->eof()){
sleep(1);
$file->fseek(0, SEEK_CUR);
continue;
}
$file->next();
$line = rtrim($line, PHP_EOL);
}
```
The data obtained by the
$line variable may be incomplete. For example, the content of
a line is 1111111111222222222222, and the content it obtains may be
222222222222, that is, the previous content of this line is lost.
According to the statistical results of online log collection, there will be problems with about 5
lines of data in 10 million lines.
### PHP Version
7.3.28
### Operating System
CentOS release 7.6.1810