zeus/async 问题修复 & 功能扩展

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

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

zeus/async

Composer 安装命令:

composer require zeus/async

包简介

A library that can run objects async with PHP

README 文档

README

Provides async running objects with PHP via process spawn

for installation via composer

composer require zeus/async:dev-main

php test code

use Zeus\Async\AsyncProcess;
use Zeus\Async\test\Sleep;

require_once 'vendor/autoload.php';


$asyncProcess = new AsyncProcess();
$asyncProcess->add(new Sleep(2));
$asyncProcess->add(new Sleep(1));
$asyncProcess->add(new Sleep(2));
$asyncProcess->add(new Sleep(1));
$asyncProcess->add(new Sleep(3));
$asyncProcess->add(new Sleep(1));
$asyncProcess->add(new Sleep(2));
$asyncProcess->add(new Sleep(2));
$asyncProcess->add(new Sleep(1));


echo 'app started';

$asyncProcess->start();

echo 'app progressing';
$asyncProcess->wait();

echo 'app is finished';

Synchronous

If you want some objects to run in Sync, you can do this through the Mutex object.

use Zeus\Async\AsyncProcess;
use Zeus\Async\Mutex;
use Zeus\Async\test\Sleep;
use Zeus\Async\test\SleepSync;

require_once 'vendor/autoload.php';


$mutex = new Mutex();

$asyncProcess = new AsyncProcess(7);

$asyncProcess->add(new SleepSync($mutex, 2));
$asyncProcess->add(new Sleep(1));
$asyncProcess->add(new SleepSync($mutex, 2));

$asyncProcess->start();
$asyncProcess->wait();

Mutex

In critical transactions, some operations may need to wait for some operations, the best example of this is if two people try to buy a ticket at the same time, it will make one of them wait atomically.

$mutex = new Mutex();

$mutex->lock();
//critic operations 
$mutex->unlock();

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: proprietary
  • 更新时间: 2024-01-13