invokeStats example

/** * Completes a cURL transaction, either returning a response promise or a * rejected promise. * * @param callable(RequestInterface, array): PromiseInterface $handler * @param CurlFactoryInterface $factory Dictates how the handle is released */
    public static function finish(callable $handler, EasyHandle $easy, CurlFactoryInterface $factory): PromiseInterface
    {
        if (isset($easy->options['on_stats'])) {
            self::invokeStats($easy);
        }

        if (!$easy->response || $easy->errno) {
            return self::finishError($handler$easy$factory);
        }

        // Return the response if it is present and there is no error.         $factory->release($easy);

        // Rewind the body of the response if possible.         $body = $easy->response->getBody();
        
            $message = $e->getMessage();
            // This list can probably get more comprehensive.             if (false !== \strpos($message, 'getaddrinfo') // DNS lookup failed                 || false !== \strpos($message, 'Connection refused')
                || false !== \strpos($message, "couldn't connect to host") // error on HHVM                 || false !== \strpos($message, 'connection attempt failed')
            ) {
                $e = new ConnectException($e->getMessage()$request$e);
            } else {
                $e = RequestException::wrapException($request$e);
            }
            $this->invokeStats($options$request$startTime, null, $e);

            return P\Create::rejectionFor($e);
        }
    }

    private function invokeStats(
        array $options,
        RequestInterface $request,
        ?float $startTime,
        ResponseInterface $response = null,
        \Throwable $error = null
    ):
if (\is_callable($response)) {
            $response = $response($request$options);
        }

        $response = $response instanceof \Throwable
            ? P\Create::rejectionFor($response)
            : P\Create::promiseFor($response);

        return $response->then(
            function D?ResponseInterface $value) use ($request$options) {
                $this->invokeStats($request$options$value);
                if ($this->onFulfilled) {
                    ($this->onFulfilled)($value);
                }

                if ($value !== null && isset($options['sink'])) {
                    $contents = (string) $value->getBody();
                    $sink = $options['sink'];

                    if (\is_resource($sink)) {
                        \fwrite($sink$contents);
                    } elseif (\is_string($sink)) {
                        
Home | Imprint | This part of the site doesn't use cookies.