2017 © Pedro Peláez
 

library deferred

Deferred callback execution based on RAII

image

dangoodman/deferred

Deferred callback execution based on RAII

  • Wednesday, April 26, 2017
  • by dangoodman
  • Repository
  • 1 Watchers
  • 2 Stars
  • 171 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 7 % Grown

The README.md

Build Status, (*1)

Deferred

Deferred callback execution based on RAII., (*2)

Usage example:, (*3)

    function download($url, $toFile)
    {
        // Temporary increase memory limit for this function
        // $restoreMemoryLimit automatically called upon function exit
        $prevMemoryLimit = ini_get('memory_limit');
        ini_set('memory_limit', '256M');
        $restoreMemoryLimit = new Deferred(function() use($prevMemoryLimit) {
            ini_set('memory_limit', $prevMemoryLimit);
        });

        $contents = file_get_contents($url);
        if (!$contents) {
            throw new \RuntimeException("Couldn't fetch url contents");
        }

        if (file_put_contents($toFile, $contents) === false) {
            throw new \RuntimeException("Couldn't save url contents to file '{$toFile}'");
        }

        return $contents;
    }

Compare it with following example without deferreds:, (*4)

    function downloadWithouDeferred($url, $toFile)
    {
        $prevMemoryLimit = ini_get('memory_limit');
        ini_set('memory_limit', '256M');

        $contents = file_get_contents($url);
        if (!$contents) {
            ini_set('memory_limit', $prevMemoryLimit);
            throw new \RuntimeException("Couldn't fetch url contents");
        }

        if (file_put_contents($toFile, $contents) === false) {
            ini_set('memory_limit', $prevMemoryLimit);
            throw new \RuntimeException("Couldn't save url contents to file '{$toFile}'");
        }

        ini_set('memory_limit', $prevMemoryLimit);

        return $contents;
    }

The Versions

26/04 2017

dev-master

9999999-dev

Deferred callback execution based on RAII

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

26/04 2017

1.0.1

1.0.1.0

Deferred callback execution based on RAII

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

23/05 2016

1.0.0

1.0.0.0

Deferred callback execution based on RAII

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires