This function is very efficient to redirect streams. I have older scripts to compare, and recent versions of PHP are so fast, that sometimes 2 lines might get fed into one, and this happens only on PHP 8.3 and 8.4.
After digging, i found that throttling a bit is the best to do to maintain retro compatibility.
$line = stream_get_line($response, 1024, "\n");
usleep(10000);