PHPackages                             mrsuh/php-var-sizeof - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mrsuh/php-var-sizeof

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mrsuh/php-var-sizeof
====================

Provides functions for getting full size of any PHP variable

1.3.0(2y ago)6010.4k↑12.5%1MITPHPPHP &gt;=7.4

Since Jan 27Pushed 2y ago2 watchersCompare

[ Source](https://github.com/mrsuh/php-var-sizeof)[ Packagist](https://packagist.org/packages/mrsuh/php-var-sizeof)[ RSS](/packages/mrsuh-php-var-sizeof/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (2)Versions (7)Used By (0)

PHP var\_sizeof()
=================

[](#php-var_sizeof)

[![Tests](https://github.com/mrsuh/php-var-sizeof/actions/workflows/tests.yml/badge.svg)](https://github.com/mrsuh/php-var-sizeof/actions/workflows/tests.yml/badge.svg)

Function for getting size of any PHP variable in bytes.
It must be more accurate tool to calculate total size of PHP variable than `memory_get_usage()`, but it has [restrictions](#warning-restrictions).

### How it works

[](#how-it-works)

`var_sizeof()` with `var_class_sizeof()` uses FFI to access internal structures of PHP variables.
It calculates the size of internal structures such as `zval`, `_zend_array`, `_zend_object`, etc., as well as additional allocated memory for them.
It doesn't take into calculate the memory of handlers/functions/etc.

### Requirements

[](#requirements)

- PHP &gt;= 7.4 (with FFI)
- Linux(x86\_64/aarch64) / Darwin(x86\_64/arm64)

### How to install

[](#how-to-install)

```
composer require mrsuh/php-var-sizeof
```

### Functions

[](#functions)

```
int var_sizeof(mixed $var);
```

```
int var_class_sizeof(mixed $var);
```

Usage
-----

[](#usage)

```
