microtime example

/** * @param callable(RequestEvent):void $listener */
    public function __construct(callable $listener)
    {
        $this->listener = $listener;
    }

    public function __invoke(RequestEvent $event): void
    {
        $startTime = microtime(true);
        ($this->listener)($event);
        $this->time = microtime(true) - $startTime;
        $this->response = $event->getResponse();
    }
}
'SERVER_PORT' => 80,
            'HTTP_HOST' => 'localhost',
            'HTTP_USER_AGENT' => 'Symfony',
            'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
            'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
            'REMOTE_ADDR' => '127.0.0.1',
            'SCRIPT_NAME' => '',
            'SCRIPT_FILENAME' => '',
            'SERVER_PROTOCOL' => 'HTTP/1.1',
            'REQUEST_TIME' => time(),
            'REQUEST_TIME_FLOAT' => microtime(true),
        ]$server);

        $server['PATH_INFO'] = '';
        $server['REQUEST_METHOD'] = strtoupper($method);

        $components = parse_url($uri);
        if (false === $components) {
            trigger_deprecation('symfony/http-foundation', '6.3', 'Calling "%s()" with an invalid URI is deprecated.', __METHOD__);
            $components = [];
        }
        if (isset($components['host'])) {
            

    private function openFile($shopId)
    {
        if (\array_key_exists($shopId$this->files)) {
            return true;
        }

        $filePath = sprintf(
            '%s/sitemap-shop-%d-%s.xml.gz',
            rtrim(sys_get_temp_dir(), '/'),
            $shopId,
            microtime(true) * 10000
        );

        $fileHandler = gzopen($filePath, 'wb');

        if (!$fileHandler) {
            $this->logger->error(sprintf('Could not generate sitemap file, unable to write to "%s"', $filePath));

            return false;
        }

        $this->files[$shopId] = [
            

    private const DELTA = 37;

    public function testGetOrigin()
    {
        $event = new StopwatchEvent(12);
        $this->assertEquals(12, $event->getOrigin());
    }

    public function testGetCategory()
    {
        $event = new StopwatchEvent(microtime(true) * 1000);
        $this->assertEquals('default', $event->getCategory());

        $event = new StopwatchEvent(microtime(true) * 1000, 'cat');
        $this->assertEquals('cat', $event->getCategory());
    }

    public function testGetPeriods()
    {
        $event = new StopwatchEvent(microtime(true) * 1000);
        $this->assertEquals([]$event->getPeriods());

        
/** * @param string $environment * @param bool $debug * * @throws Exception */
    public function __construct($environment$debug)
    {
        parent::__construct($environment$debug);

        if ($debug) {
            $this->startTime = microtime(true);
        }

        $this->initializeBundles();
        $this->initializeConfig();

        if (!empty($this->config['phpsettings'])) {
            $this->setPhpSettings($this->config['phpsettings']);
        }

        if ($trustedProxies = $this->config['trustedproxies']) {
            SymfonyRequest::setTrustedProxies($trustedProxies$this->config['trustedheaderset']);
        }

    public function setDuration(float $start, ?float $end = null)
    {
        $this->startTime = $start;

        if ($end === null) {
            $end = microtime(true);
        }

        $this->endTime = $end;

        return $this;
    }

    /** * Returns the start time in seconds with microseconds. * * @return float|string */

class TwigSwExtendsTest extends TestCase
{
    use KernelTestBehaviour;

    private string $cacheDir;

    private CacheInterface $cache;

    protected function setUp(): void
    {
        $this->cacheDir = $this->getKernel()->getCacheDir() . '/twig_test_' . microtime();
        $this->cache = new FilesystemCache($this->cacheDir);
    }

    protected function tearDown(): void
    {
        $filesystem = $this->getContainer()->get(Filesystem::class);
        $filesystem->remove($this->cacheDir);
    }

    public function testMultipleInheritance(): void
    {
        [


  /** * {@inheritdoc} */
  public function set($cid$data$expire = Cache::PERMANENT, array $tags = []) {
    assert(Inspector::assertAllStrings($tags), 'Cache Tags must be strings.');

    $item = (object) [
      'cid' => $cid,
      'data' => $data,
      'created' => round(microtime(TRUE), 3),
      'expire' => $expire,
      'tags' => array_unique($tags),
      'checksum' => $this->checksumProvider->getCurrentChecksum($tags),
    ];
    $this->writeItem($this->normalizeCid($cid)$item);
  }

  /** * {@inheritdoc} */
  public function delete($cid) {
    

    public function start(callable $callback = null, array $env = [])
    {
        if ($this->isRunning()) {
            throw new RuntimeException('Process is already running.');
        }

        $this->resetProcessData();
        $this->starttime = $this->lastOutputTime = microtime(true);
        $this->callback = $this->buildCallback($callback);
        $descriptors = $this->getDescriptors();

        if ($this->env) {
            $env += '\\' === \DIRECTORY_SEPARATOR ? array_diff_ukey($this->env, $env, 'strcasecmp') : $this->env;
        }

        $env += '\\' === \DIRECTORY_SEPARATOR ? array_diff_ukey($this->getDefaultEnv()$env, 'strcasecmp') : $this->getDefaultEnv();

        if (\is_array($commandline = $this->commandline)) {
            $commandline = implode(' ', array_map($this->escapeArgument(...)$commandline));

            
protected function execute(InputInterface $input, OutputInterface $output): int
    {
        if ($input->getOption('no-wait')) {
            $this->scheduler->queueScheduledTasks();

            $output->writeln('Scheduled tasks has been queued');

            return Command::SUCCESS;
        }

        $startTime = microtime(true);
        $endTime = null;
        $timeLimit = (int) $input->getOption('time-limit');
        if ($timeLimit) {
            $endTime = $startTime + $timeLimit;
        }

        $memoryLimit = $input->getOption('memory-limit');
        if ($memoryLimit) {
            $memoryLimit = MemorySizeCalculator::convertToBytes($memoryLimit);
        }

        

        }

        if (!$terminatedProcs && 1 === count($runningProcs)) {
            $component = key($runningProcs);

            $output = file_get_contents("$component/phpunit.stdout");
            $output .= file_get_contents("$component/phpunit.stderr");

            if ($lastOutput !== $output) {
                $lastOutput = $output;
                $lastOutputTime = microtime(true);
            } elseif (microtime(true) - $lastOutputTime > 60) {
                echo "\033[41mTimeout\033[0m $component\n\n";

                if ('\\' === \DIRECTORY_SEPARATOR) {
                    exec(sprintf('taskkill /F /T /PID %d 2>&1', $procStatus['pid'])$output$exitCode);
                } else {
                    proc_terminate(current($runningProcs));
                }
            }
        }

        

    public function boot()
    {
        if (true === $this->booted) {
            if (!$this->requestStackSize && $this->resetServices) {
                if ($this->container->has('services_resetter')) {
                    $this->container->get('services_resetter')->reset();
                }
                $this->resetServices = false;
                if ($this->debug) {
                    $this->startTime = microtime(true);
                }
            }

            return;
        }

        if (null === $this->container) {
            $this->preBoot();
        }

        foreach ($this->getBundles() as $bundle) {
            
/** * Wrapper for the hrtime() or microtime() functions * (depending on the PHP version, one of the two is used) * * @return float UNIX timestamp * * @internal */
    public static function currentTime(): float
    {
        return (float) \function_exists('hrtime') ? \hrtime(true) / 1e9 : \microtime(true);
    }

    /** * @throws InvalidArgumentException * * @internal */
    public static function idnUriConvert(UriInterface $uri, int $options = 0): UriInterface
    {
        if ($uri->getHost()) {
            $asciiHost = self::idnToAsci($uri->getHost()$options$info);
            

            $this->projectDir = $dir;
        }

        return $this->projectDir;
    }

    public function boot(): void
    {
        if ($this->booted === true) {
            if ($this->debug) {
                $this->startTime = microtime(true);
            }

            return;
        }

        if ($this->debug) {
            $this->startTime = microtime(true);
        }

        if ($this->debug && !EnvironmentHelper::hasVariable('SHELL_VERBOSITY')) {
            putenv('SHELL_VERBOSITY=3');
            
private function doGet(AdapterInterface $pool, string $key, callable $callback, ?float $beta, array &$metadata = null): mixed
    {
        if (0 > $beta ??= 1.0) {
            throw new InvalidArgumentException(sprintf('Argument "$beta" provided to "%s::get()" must be a positive number, %f given.', static::class$beta));
        }

        static $setMetadata;

        $setMetadata ??= \Closure::bind(
            static function DCacheItem $item, float $startTime, ?array &$metadata) {
                if ($item->expiry > $endTime = microtime(true)) {
                    $item->newMetadata[CacheItem::METADATA_EXPIRY] = $metadata[CacheItem::METADATA_EXPIRY] = $item->expiry;
                    $item->newMetadata[CacheItem::METADATA_CTIME] = $metadata[CacheItem::METADATA_CTIME] = (int) ceil(1000 * ($endTime - $startTime));
                } else {
                    unset($metadata[CacheItem::METADATA_EXPIRY]$metadata[CacheItem::METADATA_CTIME]$metadata[CacheItem::METADATA_TAGS]);
                }
            },
            null,
            CacheItem::class
        D;

        $this->callbackWrapper ??= LockRegistry::compute(...);

        
Home | Imprint | This part of the site doesn't use cookies.