承接 dangoodman/deferred 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dangoodman/deferred

Composer 安装命令:

composer require dangoodman/deferred

包简介

Deferred callback execution based on RAII

README 文档

README

Build Status

Deferred

Deferred callback execution based on RAII.

Usage example:

    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:

    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;
    }

统计信息

  • 总下载量: 3.11k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-01-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固