Repository: symfony/symfony
File: src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/PostgreSqlConnection.php (PHP)

Code before:
    }

    public function __destruct()
    {
        $this->unlisten();
    }

    public function reset(): void
    {
        parent::reset();
        $this->unlisten();
    }

    public function get(): ?array
    {
        if (null === $this->queueEmptiedAt) {
            return parent::get();
        }

        // This is secure because the table name must be a valid identifier:
        // https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
        $this->executeStatement(\sprintf('LISTEN "%s"', $this->configuration['table_name']));

        /** @var \PDO $nativeConnection */
        $nativeConnection = $this->driverConnection->getNativeConnection();
        $timeout = $this->configuration['check_delayed_interval'] - dump(microtime(true) * 1000 - $this->queueEmptiedAt);
        $timeout = max(0, ceil(min($this->configuration['get_notify_timeout'] ?: $timeout, $timeout)));

        $notification = $nativeConnection->getNotify(\PDO::FETCH_ASSOC, $timeout);
        if (
            // no notifications, or for another table or queue
            (false === $notification || $notification['message'] !== $this->configuration['table_name'] || $notification['payload'] !== $this->configuration['queue_name'])
            // delayed messages
            && (microtime(true) * 1000 - $this->queueEmptiedAt < $this->configuration['check_delayed_interval'])
        ) {
            return null;
        }

        return parent::get();
    }

    private function unlisten(): void
    {
        $this->executeStatement(\sprintf('UNLISTEN "%s"', $this->configuration['table_name']));
    }
}


Review comment (suggestion):
```suggestion
        $timeout = $this->configuration['check_delayed_interval'] - microtime(true) * 1000 - $this->queueEmptiedAt;
```


Code after:
    }

    public function __destruct()
    {
        $this->unlisten();
    }

    public function reset(): void
    {
        parent::reset();
        $this->unlisten();
    }

    public function get(): ?array
    {
        if (null === $this->queueEmptiedAt) {
            return parent::get();
        }

        // This is secure because the table name must be a valid identifier:
        // https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
        $this->executeStatement(\sprintf('LISTEN "%s"', $this->configuration['table_name']));

        /** @var \PDO $nativeConnection */
        $nativeConnection = $this->driverConnection->getNativeConnection();
        $timeout = $this->configuration['check_delayed_interval'] - (microtime(true) * 1000 - $this->queueEmptiedAt);
        $timeout = max(0, ceil(min($this->configuration['get_notify_timeout'] ?: $timeout, $timeout)));

        $notification = $nativeConnection->getNotify(\PDO::FETCH_ASSOC, $timeout);
        if (
            // no notifications, or for another table or queue
            (false === $notification || $notification['message'] !== $this->configuration['table_name'] || $notification['payload'] !== $this->configuration['queue_name'])
            // delayed messages
            && (microtime(true) * 1000 - $this->queueEmptiedAt < $this->configuration['check_delayed_interval'])
        ) {
            return null;
        }

        return parent::get();
    }

    private function unlisten(): void
    {
        $this->executeStatement(\sprintf('UNLISTEN "%s"', $this->configuration['table_name']));
    }
}