public function onShutdown()

in agent/php/ElasticApm/Impl/AutoInstrument/TransactionForExtensionRequest.php [371:416]


    public function onShutdown(): void
    {
        ($loggerProxy = $this->logger->ifDebugLevelEnabled(__LINE__, __FUNCTION__))
        && $loggerProxy->log('Entered');

        PhpPartFacade::ensureHaveLatestDataDeferredByExtension();

        if ($this->inferredSpansManager !== null) {
            $this->inferredSpansManager->shutdown();
        }

        $tx = $this->transactionForRequest;
        if ($tx === null || $tx->isNoop() || $tx->hasEnded()) {
            return;
        }

        if (!self::isCliScript()) {
            $this->beforeHttpEnd($tx);
        }

        $tx->end();

        if ($this->tracer->getConfig()->devInternal()->gcCollectCyclesAfterEveryTransaction()) {
            $this->logGcStatus();

            $numberOfCollectedCycles = gc_collect_cycles();
            ($loggerProxy = $this->logger->ifDebugLevelEnabled(__LINE__, __FUNCTION__))
            && $loggerProxy->log(
                'Called gc_collect_cycles() because ' . OptionNames::DEV_INTERNAL
                . ' sub-option ' . DevInternalSubOptionNames::GC_COLLECT_CYCLES_AFTER_EVERY_TRANSACTION . ' is set',
                ['numberOfCollectedCycles' => $numberOfCollectedCycles]
            );

            $this->logGcStatus();
        }

        if ($this->tracer->getConfig()->devInternal()->gcMemCachesAfterEveryTransaction()) {
            $numberOfBytesFreed = gc_mem_caches();
            ($loggerProxy = $this->logger->ifDebugLevelEnabled(__LINE__, __FUNCTION__))
            && $loggerProxy->log(
                'Called gc_mem_caches() because ' . OptionNames::DEV_INTERNAL
                . ' sub-option ' . DevInternalSubOptionNames::GC_MEM_CACHES_AFTER_EVERY_TRANSACTION . ' is set',
                ['numberOfBytesFreed' => $numberOfBytesFreed]
            );
        }
    }