lukaszaleckas/laravel-concurrency 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

lukaszaleckas/laravel-concurrency

最新稳定版本:v1.0.0

Composer 安装命令:

composer require lukaszaleckas/laravel-concurrency

包简介

README 文档

README

Installation

  1. Run:
composer require lukaszaleckas/laravel-concurrency

Service provider should be automatically registered, if not add

LaravelConcurrency\ConcurrencyServiceProvider::class

to your application's app.php.

  1. Publish configuration file:
php artisan vendor:publish --provider="LaravelConcurrency\ConcurrencyServiceProvider"
  1. Run migrations to create tasks table:
php artisan migrate

Usage Example

Create a task

Create a new task which implements LaravelConcurrency\Contracts\TaskInterface:

use LaravelConcurrency\Contracts\TaskInterface;

class SleepForTwoSeconds implements TaskInterface
{
    public function run(): mixed
    {
        sleep(2);
        
        return null;
    }
}

Tasks return result which you want to get after running them. This can be anything you want, but it needs to be serializable.

In this example we just return null.

Spawn task workers

Tasks are run by tasks workers. To spawn a task worker run:

php artisan concurrency:run-task-worker

One worker can run only one task at a time. So we'll spawn two of those for this example.

Run tasks

Now run a couple of these tasks concurrently:

use LaravelConcurrency\Facades\Concurrency;

Concurrency::wait(
    new SleepForTwoSeconds(),
    new SleepForTwoSeconds()
)

If you notice, these tasks were both completed in ~2s, which means they've run concurrently.

You should also notice task workers logs that indicate which task ran in which process.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-04-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固