Question Details

No question body available.

Tags

php curl lichess

Answers (1)

Accepted Answer Available
Accepted Answer
July 17, 2026 Score: 4 Rep: 31,510 Quality: High Completeness: 50%

You should use CURLOPTWRITEFUNCTION instead of CURLOPTRETURNTRANSFER in order to fetch the stream data in time:

curlsetopt($ch, CURLOPTWRITEFUNCTION, function (\CurlHandle $ch, string $data) { # The tail of the stream data may not contain a complete line, # save the last element to this variable and prepend it to the next data. static $lastline = ''; $len = strlen($data); if($len > 0) { $lines = explode("\n", $data); $lines[0] = $lastline.$lines[0]; $linecount = count($lines) - 1; for($i = 0; $i < $linecount; $i++) { # handle each line here $j = json_decode($lines[$i]); } $lastline = $lines[$linecount]; } return $len; });