定制 truesocialmetrics/cdn 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

truesocialmetrics/cdn

Composer 安装命令:

composer require truesocialmetrics/cdn

包简介

Cdn helper for ZF2/ZF3/Laminas

README 文档

README

Version 2.* Created by Rostislav Mykhajliw Build Status

Introduction

TweeCdn is a list of view helpers for support css/js/images links transformation due to rules.

Requirements

  • php >= 7
  • zendframework/zend-stdlib
  • zendframework/zend-view

Features / Goals

  • Simple by adding ?timestamp marker to the end of file e.q. /css/test.css?1234567
  • Release idenitify new static files version by given REVISION number e.q. /css/1234/test.css
  • Hash build unique marker based on file md5 hash e.q. /css/af34c42/test.css. It allows users to load only changed files.
  • Multiple hostnames supports e.q. host1.com, host2.com
  • Hash generator

Installation

Main Setup

With composer

  1. Add this project and Cdn in your composer.json:

    "require": {
        "necromant2005/cdn": "*",
    }
  2. Now tell composer to download TweeCdn by running the command:

    $ php composer.phar update

Post installation

Enabling it in your "application.config.php" file.

```php
<?php
return array(
    'modules' => array(
        // ...
        'TweeCdn',
    ),
    // ...
);
```

Advanced configuration

  • type - cdn type
  • public_dir - path to public dir
  • hostnames - list available hostnames
  • hashes - hash list (file_path => hash)
  • mapping - map specific to filepath to global CDNs: Google/NetDNA/MaxCDN

Options hostnames - support ALL cdn helpers.

  1. Simple (default mode) Simple adds ?timestamp marker to the end of file Original

        /css/simple.css

    tranfromed to

        /css/simple.css?1353231966

    Configuration with mapping jquery to google CDN (https://developers.google.com/speed/libraries/devguide)

    <?php
    return array(
        'di' => array(
            'instance' => array(
                'TweeCdn\View\Helper\Cdn' => array(
                    'parameters' => array(
                        // simple configuration
                        'type'    => 'simple',
                        'options' => array(
                            'public_dir' => __DIR__ . '/../../../../public',
                            'mappings' => array(
                                '/js/jquery.js' => '//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js'
                            ),
                        ),
                    ),
                ),
            ),
        ),
    );
  2. Release Release based helper puts release number stored in file "/RELEASE" right after first folder name. As result you have unique path every release. (RELEASE file by default created by Remote multi-server automation tool - Capistrano) Original

        /css/simple.css

    tranfromed to

        /css/1353231966/simple.css

    Configuration

    <?php
    return array(
        'di' => array(
            'instance' => array(
                'TweeCdn\View\Helper\Cdn' => array(
                    'parameters' => array(
                        // simple configuration
                        'release'    => 'release',
                        'options' => array(
                            'public_dir' => __DIR__ . '/../../../../public',
                            'release' => trim(file_get_contents(__DIR__ . '/../../../../REVISION')),
                        ),
                    ),
                ),
            ),
        ),
    );
  3. Hash Hash provides almost the same to "release" but uses unique file content hash. It can works in 2 mode:

    • dynamic - when hashed generates in fly
    • pre-compiled - by using existed hash map For "pre-compiled" mode you can generate hash map files by using script. it creates tmp/hashes.php files list. Eventully it makes application faster because you make less IO disk by skiping files md5 calculation every request.
    vendor/bin/hash_collector.php
    

    Original

        /css/simple.css

    tranfromed to

        /css/72e7d8fb348a326251c37821d1b6bfe16ea69d6e/simple.css

    Configuration sample with fail-back protection of missed tmp/hashes.php file and hostnames. The files will be spreaded by cdn-0 and cdn-1 by random depends on filename.

    <?php
    return array(
        'di' => array(
            'instance' => array(
                'TweeCdn\View\Helper\Cdn' => array(
                    'parameters' => array(
                        // simple configuration
                        'release'    => 'hash',
                        'options' => array(
                            'public_dir' => __DIR__ . '/../../../../public',
                            'hostnames' => array('http://cdn-0.coockieless.domain.com', 'http://cdn-1.coockieless.domain.com'),
                            'hashes' => (file_exists(__DIR__ . '/../tmp/hashes.php')) ? include __DIR__ . '/../tmp/hashes.php' : array(),
                        ),
                    ),
                ),
            ),
        ),
    );

truesocialmetrics/cdn 适用场景与选型建议

truesocialmetrics/cdn 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.87k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 12 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cdn」 「helper」 「content」 「delivery」 「laminas」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 truesocialmetrics/cdn 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 truesocialmetrics/cdn 我们能提供哪些服务?
定制开发 / 二次开发

基于 truesocialmetrics/cdn 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-12-28