承接 practically/preloader 相关项目开发

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

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

practically/preloader

Composer 安装命令:

composer require practically/preloader

包简介

PHP preloading for PHP >=7.4

README 文档

README

PHP preloading for PHP >=7.4. Preloading is a feature of php that will pre-compile php functions and classes to opcache. Thus, this becomes available in your programs with out needing to require the files, which improves speed. To read more on php preloading you can see the opcache.preloading documentation.

Installation

The preferred method is with composer.

composer require practically/preloader

Usage

After installation you need to create a preload executable.

#!/usr/bin/env php
<?php

use Composer\Autoload\ClassLoader;
use Practically\Preloading\Preloader;

if (!function_exists('opcache_compile_file') || !ini_get('opcache.enable')) {
    echo 'Opcache is not available.';
    die(1);
}

if ('cli' === PHP_SAPI && !ini_get('opcache.enable_cli')) {
    echo 'Opcache is not enabled for CLI applications.';
    die(1);
}

/** @var ClassLoader */
$autoloader = require __DIR__ . '/vendor/autoload.php';
$preloader = new Preloader($autoloader);

/**
 * Set regex patterns of classes you want to exclude from preloading. In this
 * example any of the yii2 dev classes and the `Object` class that has been removed
 * and is no longer used
 */
$preloader->exclude('/^yii\\\composer/');
$preloader->exclude('/^yii\\\test/');
$preloader->exclude('/yii\\\base\\\Object/');

/**
 * A regex pattern of classes to preload this will get of the preloader and
 * preload all of the yii2 classes excluding the above and all of the app
 * classes
 */
$preloader->preload('/^yii/');
$preloader->preload('/^app/');

/**
 * Preload a directory of php files recucivly
 */
$preloader->preloadDirectory(__DIR__ . '/views');

The preloader uses the composer class map under the hood, so you will need to generate the class map using composer optimised autoloader with the -o flag when running composer.

composer install -o

Once all that is done you will need to configure you php.ini to use the preload script to preload classes and files into the opcache.

;
; Ensure opcache is enable
;
opcache.enable=1
;
; You may need to ensure opcache is enable for cli scripts if needed
;
opcache.enable_cli=1
;
; Set the path to the preload script and setup the user if needed
;
opcache.preload=/path/to/preload.php
opcache.preload_user=user

Contributing

Getting set up

Clone the repo and run composer install. Then start hacking!

Testing

All new features of bug fixes must be tested. Testing is with phpunit and can be run with the following command:

composer run-script test

Coding Standards

This library uses Practically coding standards and squizlabs/php_codesniffer for linting. There is a composer script for this:

composer run-script cs:check

Pull Requests

Before you create a pull request with you changes, the pre-commit script must pass. That can be run as follows:

composer run-script pre-commit

Credits

This package is created and maintained by Practically.io

practically/preloader 适用场景与选型建议

practically/preloader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35.97k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2021 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 35.97k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2021-04-23