use GuzzleHttp\TransferStats;
$options = [
'on_stats' => function (TransferStats $stats) {
$context = $stats->getHandlerContext();
// Safely verify if cURL was the underlying driver
if (array_key_exists('errno', $context)) {
$curlErrorCode = $context['errno'];
// This is definitively a cURL transfer
} else {
// It used a PHP Stream, MockHandler, or another abstraction
}
}
];