Parse and use Lichess stream data with cURL and PHP
22:38 16 Jul 2026

I want to stream data from Lichess to the command line. I want to parse it and use it as needed without breaking the stream. I want to do it in native PHP.

$ch      = curl_init("https://lichess.org/api/board/game/stream/{gameId}");
$options = [
 CURLOPT_HTTPHEADER => ['Authorization: Bearer {myToken}']
 ];
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);

The above will spit out ndjson every time a move is made and Lichess sends a blank line every 7 seconds to keep the stream alive.

But I can't use $result until the stream has ended. How do I use each line of ndjson as it comes in without using Guzzle or other libraries/wrappers I've seen mentioned?

Also, adding CURLOPT_RETURNTRANSFER = true to the options array will not print anything out but is needed if I want to use json_decode() later.

php terminal lichess