An open API service indexing awesome lists of open source software.

https://github.com/sakanjo/memory-limited

A package to limit the memory upon a function call.
https://github.com/sakanjo/memory-limited

ini php

Last synced: 10 months ago
JSON representation

A package to limit the memory upon a function call.

Awesome Lists containing this project

README

          

Memory limited


PHP 8.0

Don't eat my memory please

> ✨ Help support the maintenance of this package by [sponsoring me](https://github.com/sponsors/sakanjo).

Table of contents
=================

* [Install](#install)
* [Usage](#usage)
* [Support the development](#support-the-development)
* [Credits](#credits)
* [License](#license)

## đŸ“Ļ Install

```
composer require --dev sakanjo/memory-limited
```

## đŸĻ„ Usage

```php
use function Sakanjo\MemoryLimited\run_memory_limited;

function memoryEater(): mixed
{
return memoryEater();
}

run_memory_limited(mb: 20, callback: function() {
memoryEater(); // It will throw FATAL when reaching 20M of memory, instead of hanging the system
});
```

Voila, that's it!

> Pay attention that this package is only used in **development** mode for testing purposes,
> it will throw **Fatal error** when the memory limit is reached.

## 💖 Support the development

**Do you like this project? Support it by donating**

Click the ["💖 Sponsor"](https://github.com/sponsors/sakanjo) at the top of this repo.

## ÂŠī¸ Credits

- [Salah Kanjo](https://github.com/sakanjo)
- [All Contributors](../../contributors)

## 📄 License

[MIT License](https://github.com/sakanjo/sakanjo/memory-limited/blob/master/LICENSE) Š 2023-PRESENT [Salah Kanjo](https://github.com/sakanjo)