Giter Club home page Giter Club logo

php-memory's Introduction

PHP Memory Limit

A simple tool to provide an easy-to-use API to convert memory limit configuration from php.ini to bytes.

Why

Core directive memory_limit in php.ini is a simple string. An administrator or a programmer can set several valid values, e.g.:

  • 500 = 500 bytes
  • 128M = 134 217 728 bytes
  • 1G = 1 073 741 824 bytes

You can obtain the original string value through ini_get('memory_limit') function. However, there is no built-in PHP function to provide an easy access to the byte value.

Installation

Add the package to your composer.json:

composer require brandembassy/php-memory

Usage

Create the MemoryLimitProvider service (or better, inject it using your DI container):

$configuration = new \BrandEmbassy\Memory\MemoryConfiguration();
$limitProvider = new \BrandEmbassy\Memory\MemoryLimitProvider($configuration);

There is also a DI extension for Nette Framework (you must have the nette/di package installed). Just register it in your services.neon file:

extensions:
    - BrandEmbassy\Memory\Bridge\MemoryLimitNetteExtension

You can then access the byte value of PHP memory limit like this:

$limitInBytes = $memoryLimitProvider->getLimitInBytes();

Any questions or ideas to improve? Feel free to open an issue or send a PR!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.