get($url, [ 'Content-Type' => 'application/json' ]); }); $stream = new ReadableResourceStream(fopen($filename, 'r'), $loop); $stream->on('data', function ($data) use ($browser, $queue, &$count, $endpoint) { // Process each line (data) received from the stream $lines = explode("\n", $data); foreach ($lines as $line) { // Do something with each line echo $line . PHP_EOL; $queue($endpoint.$line) ->then( function (ResponseInterface $response) use ($line) { $result = json_decode((string) $response->getBody(), true); echo 'product '.($result['Content']['ProductCode']).' exist'.PHP_EOL; }, function (Exception $e) use ($line) { echo 'missing '.$line.PHP_EOL; } ); } }); // Handle errors $stream->on('error', function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); // Handle end of file (EOF) $stream->on('end', function () use ($loop) { echo 'finished raising requests'; // Close the event loop when the stream ends (EOF) }); // Start the event loop $loop->run();