Title: Stream::getSize
Published: May 20, 2026
Last modified: August 20, 2026

---

# Stream::getSize()

## Source

    ```php
    public function getSize(): ?int
    {
        if (null !== $this->size) {
            return $this->size;
        }
        if (!isset($this->stream)) {
            return null;
        }
        // Clear the stat cache if the stream has a URI
        if ($uri = $this->getUri()) {
            \clearstatcache(\true, $uri);
        }
        $stats = \fstat($this->stream);
        if (isset($stats['size'])) {
            $this->size = $stats['size'];
            return $this->size;
        }
        return null;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/third-party/nyholm/psr7/stream.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/php-ai-client/third-party/Nyholm/Psr7/Stream.php#L106)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/php-ai-client/third-party/Nyholm/Psr7/Stream.php#L106-L124)

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwordpress-aiclientdependencies-nyholm-psr7-stream%2Fgetsize%2F)
before being able to contribute a note or feedback.