vendor/symfony/http-client/Response/CurlResponse.php line 105

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\HttpClient\Response;
  11. use Psr\Log\LoggerInterface;
  12. use Symfony\Component\HttpClient\Chunk\FirstChunk;
  13. use Symfony\Component\HttpClient\Chunk\InformationalChunk;
  14. use Symfony\Component\HttpClient\Exception\TransportException;
  15. use Symfony\Component\HttpClient\Internal\Canary;
  16. use Symfony\Component\HttpClient\Internal\ClientState;
  17. use Symfony\Component\HttpClient\Internal\CurlClientState;
  18. use Symfony\Contracts\HttpClient\ResponseInterface;
  19. /**
  20.  * @author Nicolas Grekas <p@tchwork.com>
  21.  *
  22.  * @internal
  23.  */
  24. final class CurlResponse implements ResponseInterfaceStreamableInterface
  25. {
  26.     use CommonResponseTrait {
  27.         getContent as private doGetContent;
  28.     }
  29.     use TransportResponseTrait;
  30.     private static $performing false;
  31.     private $multi;
  32.     private $debugBuffer;
  33.     /**
  34.      * @param \CurlHandle|resource|string $ch
  35.      *
  36.      * @internal
  37.      */
  38.     public function __construct(CurlClientState $multi$ch, array $options nullLoggerInterface $logger nullstring $method 'GET', callable $resolveRedirect nullint $curlVersion null)
  39.     {
  40.         $this->multi $multi;
  41.         if (\is_resource($ch) || $ch instanceof \CurlHandle) {
  42.             $this->handle $ch;
  43.             $this->debugBuffer fopen('php://temp''w+');
  44.             if (0x074000 === $curlVersion) {
  45.                 fwrite($this->debugBuffer'Due to a bug in curl 7.64.0, the debug log is disabled; use another version to work around the issue.');
  46.             } else {
  47.                 curl_setopt($ch\CURLOPT_VERBOSEtrue);
  48.                 curl_setopt($ch\CURLOPT_STDERR$this->debugBuffer);
  49.             }
  50.         } else {
  51.             $this->info['url'] = $ch;
  52.             $ch $this->handle;
  53.         }
  54.         $this->id $id = (int) $ch;
  55.         $this->logger $logger;
  56.         $this->shouldBuffer $options['buffer'] ?? true;
  57.         $this->timeout $options['timeout'] ?? null;
  58.         $this->info['http_method'] = $method;
  59.         $this->info['user_data'] = $options['user_data'] ?? null;
  60.         $this->info['start_time'] = $this->info['start_time'] ?? microtime(true);
  61.         $info = &$this->info;
  62.         $headers = &$this->headers;
  63.         $debugBuffer $this->debugBuffer;
  64.         if (!$info['response_headers']) {
  65.             // Used to keep track of what we're waiting for
  66.             curl_setopt($ch\CURLOPT_PRIVATE\in_array($method, ['GET''HEAD''OPTIONS''TRACE'], true) && 1.0 < (float) ($options['http_version'] ?? 1.1) ? 'H2' 'H0'); // H = headers + retry counter
  67.         }
  68.         curl_setopt($ch\CURLOPT_HEADERFUNCTION, static function ($chstring $data) use (&$info, &$headers$options$multi$id, &$location$resolveRedirect$logger): int {
  69.             if (!== substr_compare($data"\r\n", -2)) {
  70.                 return 0;
  71.             }
  72.             $len 0;
  73.             foreach (explode("\r\n"substr($data0, -2)) as $data) {
  74.                 $len += self::parseHeaderLine($ch$data$info$headers$options$multi$id$location$resolveRedirect$logger);
  75.             }
  76.             return $len;
  77.         });
  78.         if (null === $options) {
  79.             // Pushed response: buffer until requested
  80.             curl_setopt($ch\CURLOPT_WRITEFUNCTION, static function ($chstring $data) use ($multi$id): int {
  81.                 $multi->handlesActivity[$id][] = $data;
  82.                 curl_pause($ch\CURLPAUSE_RECV);
  83.                 return \strlen($data);
  84.             });
  85.             return;
  86.         }
  87.         $execCounter $multi->execCounter;
  88.         $this->info['pause_handler'] = static function (float $duration) use ($ch$multi$execCounter) {
  89.             if ($duration) {
  90.                 if ($execCounter === $multi->execCounter) {
  91.                     $multi->execCounter = !\is_float($execCounter) ? $execCounter \PHP_INT_MIN;
  92.                     curl_multi_remove_handle($multi->handle$ch);
  93.                 }
  94.                 $lastExpiry end($multi->pauseExpiries);
  95.                 $multi->pauseExpiries[(int) $ch] = $duration += microtime(true);
  96.                 if (false !== $lastExpiry && $lastExpiry $duration) {
  97.                     asort($multi->pauseExpiries);
  98.                 }
  99.                 curl_pause($ch\CURLPAUSE_ALL);
  100.             } else {
  101.                 unset($multi->pauseExpiries[(int) $ch]);
  102.                 curl_pause($ch\CURLPAUSE_CONT);
  103.                 curl_multi_add_handle($multi->handle$ch);
  104.             }
  105.         };
  106.         $this->inflate = !isset($options['normalized_headers']['accept-encoding']);
  107.         curl_pause($ch\CURLPAUSE_CONT);
  108.         if ($onProgress $options['on_progress']) {
  109.             $url = isset($info['url']) ? ['url' => $info['url']] : [];
  110.             curl_setopt($ch\CURLOPT_NOPROGRESSfalse);
  111.             curl_setopt($ch\CURLOPT_PROGRESSFUNCTION, static function ($ch$dlSize$dlNow) use ($onProgress, &$info$url$multi$debugBuffer) {
  112.                 try {
  113.                     rewind($debugBuffer);
  114.                     $debug = ['debug' => stream_get_contents($debugBuffer)];
  115.                     $onProgress($dlNow$dlSize$url curl_getinfo($ch) + $info $debug);
  116.                 } catch (\Throwable $e) {
  117.                     $multi->handlesActivity[(int) $ch][] = null;
  118.                     $multi->handlesActivity[(int) $ch][] = $e;
  119.                     return 1// Abort the request
  120.                 }
  121.                 return null;
  122.             });
  123.         }
  124.         curl_setopt($ch\CURLOPT_WRITEFUNCTION, static function ($chstring $data) use ($multi$id): int {
  125.             if ('H' === (curl_getinfo($ch\CURLINFO_PRIVATE)[0] ?? null)) {
  126.                 $multi->handlesActivity[$id][] = null;
  127.                 $multi->handlesActivity[$id][] = new TransportException(sprintf('Unsupported protocol for "%s"'curl_getinfo($ch\CURLINFO_EFFECTIVE_URL)));
  128.                 return 0;
  129.             }
  130.             curl_setopt($ch\CURLOPT_WRITEFUNCTION, static function ($chstring $data) use ($multi$id): int {
  131.                 $multi->handlesActivity[$id][] = $data;
  132.                 return \strlen($data);
  133.             });
  134.             $multi->handlesActivity[$id][] = $data;
  135.             return \strlen($data);
  136.         });
  137.         $this->initializer = static function (self $response) {
  138.             $waitFor curl_getinfo($ch $response->handle\CURLINFO_PRIVATE);
  139.             return 'H' === $waitFor[0];
  140.         };
  141.         // Schedule the request in a non-blocking way
  142.         $multi->lastTimeout null;
  143.         $multi->openHandles[$id] = [$ch$options];
  144.         curl_multi_add_handle($multi->handle$ch);
  145.         $this->canary = new Canary(static function () use ($ch$multi$id) {
  146.             unset($multi->pauseExpiries[$id], $multi->openHandles[$id], $multi->handlesActivity[$id]);
  147.             curl_setopt($ch\CURLOPT_PRIVATE'_0');
  148.             if (self::$performing) {
  149.                 return;
  150.             }
  151.             curl_multi_remove_handle($multi->handle$ch);
  152.             curl_setopt_array($ch, [
  153.                 \CURLOPT_NOPROGRESS => true,
  154.                 \CURLOPT_PROGRESSFUNCTION => null,
  155.                 \CURLOPT_HEADERFUNCTION => null,
  156.                 \CURLOPT_WRITEFUNCTION => null,
  157.                 \CURLOPT_READFUNCTION => null,
  158.                 \CURLOPT_INFILE => null,
  159.             ]);
  160.             if (!$multi->openHandles) {
  161.                 // Schedule DNS cache eviction for the next request
  162.                 $multi->dnsCache->evictions $multi->dnsCache->evictions ?: $multi->dnsCache->removals;
  163.                 $multi->dnsCache->removals $multi->dnsCache->hostnames = [];
  164.             }
  165.         });
  166.     }
  167.     /**
  168.      * {@inheritdoc}
  169.      */
  170.     public function getInfo(string $type null)
  171.     {
  172.         if (!$info $this->finalInfo) {
  173.             $info array_merge($this->infocurl_getinfo($this->handle));
  174.             $info['url'] = $this->info['url'] ?? $info['url'];
  175.             $info['redirect_url'] = $this->info['redirect_url'] ?? null;
  176.             // workaround curl not subtracting the time offset for pushed responses
  177.             if (isset($this->info['url']) && $info['start_time'] / 1000 $info['total_time']) {
  178.                 $info['total_time'] -= $info['starttransfer_time'] ?: $info['total_time'];
  179.                 $info['starttransfer_time'] = 0.0;
  180.             }
  181.             rewind($this->debugBuffer);
  182.             $info['debug'] = stream_get_contents($this->debugBuffer);
  183.             $waitFor curl_getinfo($this->handle\CURLINFO_PRIVATE);
  184.             if ('H' !== $waitFor[0] && 'C' !== $waitFor[0]) {
  185.                 curl_setopt($this->handle\CURLOPT_VERBOSEfalse);
  186.                 rewind($this->debugBuffer);
  187.                 ftruncate($this->debugBuffer0);
  188.                 $this->finalInfo $info;
  189.             }
  190.         }
  191.         return null !== $type $info[$type] ?? null $info;
  192.     }
  193.     /**
  194.      * {@inheritdoc}
  195.      */
  196.     public function getContent(bool $throw true): string
  197.     {
  198.         $performing self::$performing;
  199.         self::$performing $performing || '_0' === curl_getinfo($this->handle\CURLINFO_PRIVATE);
  200.         try {
  201.             return $this->doGetContent($throw);
  202.         } finally {
  203.             self::$performing $performing;
  204.         }
  205.     }
  206.     public function __destruct()
  207.     {
  208.         try {
  209.             if (null === $this->timeout) {
  210.                 return; // Unused pushed response
  211.             }
  212.             $this->doDestruct();
  213.         } finally {
  214.             curl_setopt($this->handle\CURLOPT_VERBOSEfalse);
  215.         }
  216.     }
  217.     /**
  218.      * {@inheritdoc}
  219.      */
  220.     private static function schedule(self $response, array &$runningResponses): void
  221.     {
  222.         if (isset($runningResponses[$i = (int) $response->multi->handle])) {
  223.             $runningResponses[$i][1][$response->id] = $response;
  224.         } else {
  225.             $runningResponses[$i] = [$response->multi, [$response->id => $response]];
  226.         }
  227.         if ('_0' === curl_getinfo($ch $response->handle\CURLINFO_PRIVATE)) {
  228.             // Response already completed
  229.             $response->multi->handlesActivity[$response->id][] = null;
  230.             $response->multi->handlesActivity[$response->id][] = null !== $response->info['error'] ? new TransportException($response->info['error']) : null;
  231.         }
  232.     }
  233.     /**
  234.      * {@inheritdoc}
  235.      *
  236.      * @param CurlClientState $multi
  237.      */
  238.     private static function perform(ClientState $multi, array &$responses null): void
  239.     {
  240.         if (self::$performing) {
  241.             if ($responses) {
  242.                 $response current($responses);
  243.                 $multi->handlesActivity[(int) $response->handle][] = null;
  244.                 $multi->handlesActivity[(int) $response->handle][] = new TransportException(sprintf('Userland callback cannot use the client nor the response while processing "%s".'curl_getinfo($response->handle\CURLINFO_EFFECTIVE_URL)));
  245.             }
  246.             return;
  247.         }
  248.         try {
  249.             self::$performing true;
  250.             ++$multi->execCounter;
  251.             $active 0;
  252.             while (\CURLM_CALL_MULTI_PERFORM === ($err curl_multi_exec($multi->handle$active))) {
  253.             }
  254.             if (\CURLM_OK !== $err) {
  255.                 throw new TransportException(curl_multi_strerror($err));
  256.             }
  257.             while ($info curl_multi_info_read($multi->handle)) {
  258.                 if (\CURLMSG_DONE !== $info['msg']) {
  259.                     continue;
  260.                 }
  261.                 $result $info['result'];
  262.                 $id = (int) $ch $info['handle'];
  263.                 $waitFor = @curl_getinfo($ch\CURLINFO_PRIVATE) ?: '_0';
  264.                 if (\in_array($result, [\CURLE_SEND_ERROR\CURLE_RECV_ERROR/*CURLE_HTTP2*/ 16/*CURLE_HTTP2_STREAM*/ 92], true) && $waitFor[1] && 'C' !== $waitFor[0]) {
  265.                     curl_multi_remove_handle($multi->handle$ch);
  266.                     $waitFor[1] = (string) ((int) $waitFor[1] - 1); // decrement the retry counter
  267.                     curl_setopt($ch\CURLOPT_PRIVATE$waitFor);
  268.                     curl_setopt($ch\CURLOPT_FORBID_REUSEtrue);
  269.                     if (=== curl_multi_add_handle($multi->handle$ch)) {
  270.                         continue;
  271.                     }
  272.                 }
  273.                 if (\CURLE_RECV_ERROR === $result && 'H' === $waitFor[0] && 400 <= ($responses[(int) $ch]->info['http_code'] ?? 0)) {
  274.                     $multi->handlesActivity[$id][] = new FirstChunk();
  275.                 }
  276.                 $multi->handlesActivity[$id][] = null;
  277.                 $multi->handlesActivity[$id][] = \in_array($result, [\CURLE_OK\CURLE_TOO_MANY_REDIRECTS], true) || '_0' === $waitFor || curl_getinfo($ch\CURLINFO_SIZE_DOWNLOAD) === curl_getinfo($ch\CURLINFO_CONTENT_LENGTH_DOWNLOAD) ? null : new TransportException(ucfirst(curl_error($ch) ?: curl_strerror($result)).sprintf(' for "%s".'curl_getinfo($ch\CURLINFO_EFFECTIVE_URL)));
  278.             }
  279.         } finally {
  280.             self::$performing false;
  281.         }
  282.     }
  283.     /**
  284.      * {@inheritdoc}
  285.      *
  286.      * @param CurlClientState $multi
  287.      */
  288.     private static function select(ClientState $multifloat $timeout): int
  289.     {
  290.         if (\PHP_VERSION_ID 70211) {
  291.             // workaround https://bugs.php.net/76480
  292.             $timeout min($timeout0.01);
  293.         }
  294.         if ($multi->pauseExpiries) {
  295.             $now microtime(true);
  296.             foreach ($multi->pauseExpiries as $id => $pauseExpiry) {
  297.                 if ($now $pauseExpiry) {
  298.                     $timeout min($timeout$pauseExpiry $now);
  299.                     break;
  300.                 }
  301.                 unset($multi->pauseExpiries[$id]);
  302.                 curl_pause($multi->openHandles[$id][0], \CURLPAUSE_CONT);
  303.                 curl_multi_add_handle($multi->handle$multi->openHandles[$id][0]);
  304.             }
  305.         }
  306.         if (!== $selected curl_multi_select($multi->handle$timeout)) {
  307.             return $selected;
  308.         }
  309.         if ($multi->pauseExpiries && $timeout -= microtime(true) - $now) {
  310.             usleep((int) (1E6 $timeout));
  311.         }
  312.         return 0;
  313.     }
  314.     /**
  315.      * Parses header lines as curl yields them to us.
  316.      */
  317.     private static function parseHeaderLine($chstring $data, array &$info, array &$headers, ?array $optionsCurlClientState $multiint $id, ?string &$location, ?callable $resolveRedirect, ?LoggerInterface $logger): int
  318.     {
  319.         $waitFor = @curl_getinfo($ch\CURLINFO_PRIVATE) ?: '_0';
  320.         if ('H' !== $waitFor[0]) {
  321.             return \strlen($data); // Ignore HTTP trailers
  322.         }
  323.         if ('' !== $data) {
  324.             // Regular header line: add it to the list
  325.             self::addResponseHeaders([$data], $info$headers);
  326.             if (!str_starts_with($data'HTTP/')) {
  327.                 if (=== stripos($data'Location:')) {
  328.                     $location trim(substr($data9));
  329.                 }
  330.                 return \strlen($data);
  331.             }
  332.             if (\function_exists('openssl_x509_read') && $certinfo curl_getinfo($ch\CURLINFO_CERTINFO)) {
  333.                 $info['peer_certificate_chain'] = array_map('openssl_x509_read'array_column($certinfo'Cert'));
  334.             }
  335.             if (300 <= $info['http_code'] && $info['http_code'] < 400) {
  336.                 if (curl_getinfo($ch\CURLINFO_REDIRECT_COUNT) === $options['max_redirects']) {
  337.                     curl_setopt($ch\CURLOPT_FOLLOWLOCATIONfalse);
  338.                 } elseif (303 === $info['http_code'] || ('POST' === $info['http_method'] && \in_array($info['http_code'], [301302], true))) {
  339.                     $info['http_method'] = 'HEAD' === $info['http_method'] ? 'HEAD' 'GET';
  340.                     curl_setopt($ch\CURLOPT_POSTFIELDS'');
  341.                 }
  342.             }
  343.             return \strlen($data);
  344.         }
  345.         // End of headers: handle informational responses, redirects, etc.
  346.         if (200 $statusCode curl_getinfo($ch\CURLINFO_RESPONSE_CODE)) {
  347.             $multi->handlesActivity[$id][] = new InformationalChunk($statusCode$headers);
  348.             $location null;
  349.             return \strlen($data);
  350.         }
  351.         $info['redirect_url'] = null;
  352.         if (300 <= $statusCode && $statusCode 400 && null !== $location) {
  353.             if (null === $info['redirect_url'] = $resolveRedirect($ch$location)) {
  354.                 $options['max_redirects'] = curl_getinfo($ch\CURLINFO_REDIRECT_COUNT);
  355.                 curl_setopt($ch\CURLOPT_FOLLOWLOCATIONfalse);
  356.                 curl_setopt($ch\CURLOPT_MAXREDIRS$options['max_redirects']);
  357.             } else {
  358.                 $url parse_url($location ?? ':');
  359.                 if (isset($url['host']) && null !== $ip $multi->dnsCache->hostnames[$url['host'] = strtolower($url['host'])] ?? null) {
  360.                     // Populate DNS cache for redirects if needed
  361.                     $port $url['port'] ?? ('http' === ($url['scheme'] ?? parse_url(curl_getinfo($ch\CURLINFO_EFFECTIVE_URL), \PHP_URL_SCHEME)) ? 80 443);
  362.                     curl_setopt($ch\CURLOPT_RESOLVE, ["{$url['host']}:$port:$ip"]);
  363.                     $multi->dnsCache->removals["-{$url['host']}:$port"] = "-{$url['host']}:$port";
  364.                 }
  365.             }
  366.         }
  367.         if (401 === $statusCode && isset($options['auth_ntlm']) && === strncasecmp($headers['www-authenticate'][0] ?? '''NTLM '5)) {
  368.             // Continue with NTLM auth
  369.         } elseif ($statusCode 300 || 400 <= $statusCode || null === $location || curl_getinfo($ch\CURLINFO_REDIRECT_COUNT) === $options['max_redirects']) {
  370.             // Headers and redirects completed, time to get the response's content
  371.             $multi->handlesActivity[$id][] = new FirstChunk();
  372.             if ('HEAD' === $info['http_method'] || \in_array($statusCode, [204304], true)) {
  373.                 $waitFor '_0'// no content expected
  374.                 $multi->handlesActivity[$id][] = null;
  375.                 $multi->handlesActivity[$id][] = null;
  376.             } else {
  377.                 $waitFor[0] = 'C'// C = content
  378.             }
  379.             curl_setopt($ch\CURLOPT_PRIVATE$waitFor);
  380.         } elseif (null !== $info['redirect_url'] && $logger) {
  381.             $logger->info(sprintf('Redirecting: "%s %s"'$info['http_code'], $info['redirect_url']));
  382.         }
  383.         $location null;
  384.         return \strlen($data);
  385.     }
  386. }
HTTP/2 401 returned for "https://api.hubapi.com/cms/v3/blogs/authors?hapikey=41d1972b-a2ce-454d-9e57-cd6355e00240". (500 Internal Server Error)

Symfony Exception

ClientException

HTTP 500 Internal Server Error

HTTP/2 401 returned for "https://api.hubapi.com/cms/v3/blogs/authors?hapikey=41d1972b-a2ce-454d-9e57-cd6355e00240".

Exception

Symfony\Component\HttpClient\Exception\ ClientException

  1.         if (500 <= $code) {
  2.             throw new ServerException($this);
  3.         }
  4.         if (400 <= $code) {
  5.             throw new ClientException($this);
  6.         }
  7.         if (300 <= $code) {
  8.             throw new RedirectionException($this);
  9.         }
  1.         } finally {
  2.             if ($this->event && $this->event->isStarted()) {
  3.                 $this->event->stop();
  4.             }
  5.             if ($throw) {
  6.                 $this->checkStatusCode($this->response->getStatusCode());
  7.             }
  8.         }
  9.     }
  10.     public function toArray(bool $throw true): array
TraceableResponse->getContent() in src/Blog.php (line 181)
  1.                     'hapikey' => $this->hubSpotKey,
  2.                     'after' => $after,
  3.                 ],
  4.             ]);
  5.             $result json_decode($response->getContent(), true);
  6.         } catch (HttpExceptionInterface $e) {
  7.             $this->logger->error('Could not load blog posts from HubSpot', ['exception' => $e]);
  8.             throw $e;
  9.         }
Blog->loadBlogAuthors() in src/Blog.php (line 152)
  1.         if (!isset($this->authors)) {
  2.             $beta $bustCache INF null;
  3.             $this->authors $this->cache->get('blog_authors', function (ItemInterface $item) {
  4.                 $item->expiresAfter(86400); // cache for 1 day
  5.                 return $this->loadBlogAuthors();
  6.             }, $beta);
  7.         }
  8.         return $this->authors;
  9.     }
  1.         $isHit true;
  2.         $callback = function (CacheItem $itembool &$save) use ($callback, &$isHit) {
  3.             $isHit $item->isHit();
  4.             return $callback($item$save);
  5.         };
  6.         $event $this->start(__FUNCTION__);
  7.         try {
  8.             $value $this->pool->get($key$callback$beta$metadata);
in vendor/symfony/cache/LockRegistry.php -> Symfony\Component\Cache\Adapter\{closure} (line 108)
  1.                 if ($locked || !$wouldBlock) {
  2.                     $logger && $logger->info(sprintf('Lock %s, now computing item "{key}"'$locked 'acquired' 'not supported'), ['key' => $item->getKey()]);
  3.                     self::$lockedFiles[$key] = true;
  4.                     $value $callback($item$save);
  5.                     if ($save) {
  6.                         if ($setMetadata) {
  7.                             $setMetadata($item);
  8.                         }
  1.             }
  2.             try {
  3.                 $value = ($this->callbackWrapper)($callback$item$save$pool, function (CacheItem $item) use ($setMetadata$startTime, &$metadata) {
  4.                     $setMetadata($item$startTime$metadata);
  5.                 }, $this->logger ?? null);
  6.                 $setMetadata($item$startTime$metadata);
  7.                 return $value;
  8.             } finally {
  9.                 unset($this->computing[$key]);
in vendor/symfony/cache-contracts/CacheTrait.php -> Symfony\Component\Cache\Traits\{closure} (line 72)
  1.             }
  2.         }
  3.         if ($recompute) {
  4.             $save true;
  5.             $item->set($callback($item$save));
  6.             if ($save) {
  7.                 $pool->save($item);
  8.             }
  9.         }
  1.                 return $value;
  2.             } finally {
  3.                 unset($this->computing[$key]);
  4.             }
  5.         }, $beta$metadata$this->logger ?? null);
  6.     }
  7. }
  1.      *
  2.      * @return mixed
  3.      */
  4.     public function get(string $key, callable $callbackfloat $beta null, array &$metadata null)
  5.     {
  6.         return $this->doGet($this$key$callback$beta$metadata);
  7.     }
  8.     /**
  9.      * {@inheritdoc}
  10.      */
  1.             return $callback($item$save);
  2.         };
  3.         $event $this->start(__FUNCTION__);
  4.         try {
  5.             $value $this->pool->get($key$callback$beta$metadata);
  6.             $event->result[$key] = get_debug_type($value);
  7.         } finally {
  8.             $event->end microtime(true);
  9.         }
  10.         if ($isHit) {
TraceableAdapter->get('blog_authors', object(Closure), INF) in src/Blog.php (line 149)
  1.     public function getAuthors(bool $bustCache false): array
  2.     {
  3.         if (!isset($this->authors)) {
  4.             $beta $bustCache INF null;
  5.             $this->authors $this->cache->get('blog_authors', function (ItemInterface $item) {
  6.                 $item->expiresAfter(86400); // cache for 1 day
  7.                 return $this->loadBlogAuthors();
  8.             }, $beta);
  9.         }
Blog->getAuthors(true) in src/Blog.php (line 37)
  1.      * WARNING: This will be slow and should not be called
  2.      * unless intentional.
  3.      */
  4.     public function bustCache(): void
  5.     {
  6.         $this->getAuthors(true);
  7.         $this->getTags(true);
  8.         $this->getAllPosts(true);
  9.     }
  10.     public function getAuthor(string $slug): ?array
  1.         // Update the last refresh time now to minimize cache stampede
  2.         $this->cache->get('lastContentRefresh', function () {
  3.             return time();
  4.         }, INF);
  5.         $this->blog->bustCache();
  6.     }
  7.     public static function getSubscribedEvents(): array
  8.     {
  9.         return [
ContentRefreshSubscriber->refresh() in src/EventSubscriber/ContentRefreshSubscriber.php (line 34)
  1.         $lastRefresh $this->cache->get('lastContentRefresh', function () {
  2.             return 0;
  3.         });
  4.         if ($lastRefresh strtotime('-5 minutes')) {
  5.             $this->refresh();
  6.         }
  7.     }
  8.     private function refresh(): void
  9.     {
  1.                     $closure = static function (...$args) use (&$listener, &$closure) {
  2.                         if ($listener[0] instanceof \Closure) {
  3.                             $listener[0] = $listener[0]();
  4.                             $listener[1] = $listener[1] ?? '__invoke';
  5.                         }
  6.                         ($closure \Closure::fromCallable($listener))(...$args);
  7.                     };
  8.                 } else {
  9.                     $closure $listener instanceof \Closure || $listener instanceof WrappedListener $listener \Closure::fromCallable($listener);
  10.                 }
  11.             }
in vendor/symfony/event-dispatcher/EventDispatcher.php :: Symfony\Component\EventDispatcher\{closure} (line 230)
  1.         foreach ($listeners as $listener) {
  2.             if ($stoppable && $event->isPropagationStopped()) {
  3.                 break;
  4.             }
  5.             $listener($event$eventName$this);
  6.         }
  7.     }
  8.     /**
  9.      * Sorts the internal list of listeners for the given event by priority.
  1.         } else {
  2.             $listeners $this->getListeners($eventName);
  3.         }
  4.         if ($listeners) {
  5.             $this->callListeners($listeners$eventName$event);
  6.         }
  7.         return $event;
  8.     }
  1.     /**
  2.      * {@inheritdoc}
  3.      */
  4.     public function terminate(Request $requestResponse $response)
  5.     {
  6.         $this->dispatcher->dispatch(new TerminateEvent($this$request$response), KernelEvents::TERMINATE);
  7.     }
  8.     /**
  9.      * @internal
  10.      */
in vendor/symfony/http-kernel/Kernel.php -> terminate (line 159)
  1.         if (false === $this->booted) {
  2.             return;
  3.         }
  4.         if ($this->getHttpKernel() instanceof TerminableInterface) {
  5.             $this->getHttpKernel()->terminate($request$response);
  6.         }
  7.     }
  8.     /**
  9.      * {@inheritdoc}
Kernel->terminate(object(Request), object(Response)) in public/index.php (line 36)
  1. $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
  2. $request Request::createFromGlobals();
  3. $response $kernel->handle($request);
  4. $response->send();
  5. $kernel->terminate($request$response);

Logs 3

Level Channel Message
INFO 08:51:24 php User Deprecated: Since symfony/framework-bundle 5.3: The "session.storage.native" service is deprecated, use "session.storage.factory.native" instead.
{
    "exception": {}
}
INFO 08:51:24 php User Deprecated: Since symfony/framework-bundle 5.3: The "session.storage.metadata_bag" service is deprecated, create your own "session.storage.factory" instead.
{
    "exception": {}
}
INFO 08:51:24 request Matched route "_profiler_open_file".
{
    "route": "_profiler_open_file",
    "route_parameters": {
        "_route": "_profiler_open_file",
        "_controller": "web_profiler.controller.profiler::openAction"
    },
    "request_uri": "http://invoiced.project-release.info/_profiler/open?file=vendor%2Fsymfony%2Fhttp-client%2FResponse%2FCurlResponse.php&line=105",
    "method": "GET"
}
INFO 08:51:24 cache Lock acquired, now computing item "lastContentRefresh"
{
    "key": "lastContentRefresh"
}
INFO 08:51:24 cache Lock acquired, now computing item "blog_authors"
{
    "key": "blog_authors"
}
INFO 08:51:24 http_client Request: "GET https://api.hubapi.com/cms/v3/blogs/authors?hapikey=41d1972b-a2ce-454d-9e57-cd6355e00240"
INFO 08:51:24 http_client Response: "401 https://api.hubapi.com/cms/v3/blogs/authors?hapikey=41d1972b-a2ce-454d-9e57-cd6355e00240"
ERROR 08:51:24 app Could not load blog posts from HubSpot
{
    "exception": {}
}
CRITICAL 08:51:24 php Uncaught Exception: HTTP/2 401 returned for "https://api.hubapi.com/cms/v3/blogs/authors?hapikey=41d1972b-a2ce-454d-9e57-cd6355e00240".
{
    "exception": {}
}
CRITICAL 08:51:24 request Uncaught PHP Exception Symfony\Component\HttpClient\Exception\ClientException: "HTTP/2 401 returned for "https://api.hubapi.com/cms/v3/blogs/authors?hapikey=41d1972b-a2ce-454d-9e57-cd6355e00240"." at /var/www/invoiced/data/www/invoiced.project-release.info/vendor/symfony/http-client/Response/TraceableResponse.php line 212
{
    "exception": {}
}

Stack Trace

ClientException
Symfony\Component\HttpClient\Exception\ClientException:
HTTP/2 401  returned for "https://api.hubapi.com/cms/v3/blogs/authors?hapikey=41d1972b-a2ce-454d-9e57-cd6355e00240".

  at vendor/symfony/http-client/Response/TraceableResponse.php:212
  at Symfony\Component\HttpClient\Response\TraceableResponse->checkStatusCode(401)
     (vendor/symfony/http-client/Response/TraceableResponse.php:103)
  at Symfony\Component\HttpClient\Response\TraceableResponse->getContent()
     (src/Blog.php:181)
  at App\Blog->loadBlogAuthors()
     (src/Blog.php:152)
  at App\Blog->App\{closure}(object(CacheItem), true)
     (vendor/symfony/cache/Adapter/TraceableAdapter.php:51)
  at Symfony\Component\Cache\Adapter\TraceableAdapter->Symfony\Component\Cache\Adapter\{closure}(object(CacheItem), true)
     (vendor/symfony/cache/LockRegistry.php:108)
  at Symfony\Component\Cache\LockRegistry::compute(object(Closure), object(CacheItem), true, object(FilesystemAdapter), object(Closure), object(Logger))
     (vendor/symfony/cache/Traits/ContractsTrait.php:100)
  at Symfony\Component\Cache\Adapter\AbstractAdapter->Symfony\Component\Cache\Traits\{closure}(object(CacheItem), true)
     (vendor/symfony/cache-contracts/CacheTrait.php:72)
  at Symfony\Component\Cache\Adapter\AbstractAdapter->contractsGet(object(FilesystemAdapter), 'blog_authors', object(Closure), INF, array(), object(Logger))
     (vendor/symfony/cache/Traits/ContractsTrait.php:107)
  at Symfony\Component\Cache\Adapter\AbstractAdapter->doGet(object(FilesystemAdapter), 'blog_authors', object(Closure), INF, array())
     (vendor/symfony/cache-contracts/CacheTrait.php:35)
  at Symfony\Component\Cache\Adapter\AbstractAdapter->get('blog_authors', object(Closure), INF, array())
     (vendor/symfony/cache/Adapter/TraceableAdapter.php:56)
  at Symfony\Component\Cache\Adapter\TraceableAdapter->get('blog_authors', object(Closure), INF)
     (src/Blog.php:149)
  at App\Blog->getAuthors(true)
     (src/Blog.php:37)
  at App\Blog->bustCache()
     (src/EventSubscriber/ContentRefreshSubscriber.php:45)
  at App\EventSubscriber\ContentRefreshSubscriber->refresh()
     (src/EventSubscriber/ContentRefreshSubscriber.php:34)
  at App\EventSubscriber\ContentRefreshSubscriber->onKernelTerminate(object(TerminateEvent), 'kernel.terminate', object(EventDispatcher))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:270)
  at Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}(object(TerminateEvent), 'kernel.terminate', object(EventDispatcher))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(Closure), object(Closure)), 'kernel.terminate', object(TerminateEvent))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(TerminateEvent), 'kernel.terminate')
     (vendor/symfony/http-kernel/HttpKernel.php:94)
  at Symfony\Component\HttpKernel\HttpKernel->terminate(object(Request), object(Response))
     (vendor/symfony/http-kernel/Kernel.php:159)
  at Symfony\Component\HttpKernel\Kernel->terminate(object(Request), object(Response))
     (public/index.php:36)