承接 kesha-dev/yii2-async 相关项目开发

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

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

kesha-dev/yii2-async

Composer 安装命令:

composer require kesha-dev/yii2-async

包简介

Provide an easy way to run code asynchronously for Yii2 application

README 文档

README

Latest Stable Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality Yii2

About it

An extension provide an easy way to run code asynchronous and parallel base on spatie/async wrapper for Yii2 application.

Requirements

Installation

Require Yii2 Async using Composer:

composer require vxm/yii2-async

Usage

Configure

Add the component to your application configure file:

[
    'components' => [
        'async' => [
            'class' => 'vxm\async\Async',
            'appConfigFile' => '@app/config/async.php' // optional when you need to use yii feature in async process.
        ]
    ]
]

Because async code run in difference process you need to setup yii environment to use components via property appConfigFile. Example of an async app config file:

define('YII_ENV', 'dev');
define('YII_DEBUG', true);

return [
    'id' => 'async-app',
    'basePath' => __DIR__,
    'runtimePath' => __DIR__ . '/runtime',
    'aliases' => [
        '@frontend' => dirname(__DIR__, 2) . '/frontend',
        '@backend' => dirname(__DIR__, 2) . '/backend'
    ]
];

Make sure all of your aliases define in it to support an autoload.

Run async code

After add it to application components, now you can run an async code:

Yii::$app->async->run(function() {
     // do a thing.
});

Async events

When creating asynchronous processes, you can add the following event hooks on a process in the second parameter.

Yii::$app->async->run(function() {

    if (rand(1, 2) === 1) {
    
        throw new \YourException;
    }
    
    return 123;
}, [
    'success' => function ($result) {
    
        echo $result; // 123
        
    },
    'catch' => function (\YourException $exception) {
        
        // catch only \YourException
        
    },
    'error' => function() {
    
        // catch all exceptions
        
    },
    'timeout' => function() {
    
        // call when task timeout default's 15s
        
    }
]);

Wait process

Sometime you need to wait a code executed, just call wait() after run():

Yii::$app->async->run(function() {
    // do a thing.
})->wait();

Or you can wait multi tasks executed:

Yii::$app->async->run([YourAsyncClass::class, 'handleA']);
Yii::$app->async->run([YourAsyncClass::class, 'handleD']);
Yii::$app->async->run([YourAsyncClass::class, 'handleC']);
Yii::$app->async->run([YourAsyncClass::class, 'handleD']);

$results = Yii::$app->async->wait(); // results return from tasks above.

Working with task

Besides using closures, you can also work with a Task. A Task is useful in situations where you need more setup work in the child process.

The Task class makes this easier to do.

use vxm\async\Task;

class MyTask extends Task
{

    public $productId;
    

    public function run()
    {
        // Do the real work here.
       
    }
}

// Do task async use like an anonymous above.

Yii::$app->async->run(new MyTask([
    'productId' => 123

]));

kesha-dev/yii2-async 适用场景与选型建议

kesha-dev/yii2-async 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 57 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 09 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 kesha-dev/yii2-async 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 57
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 22
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2023-09-04