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
其他信息
- 授权协议: proprietary
- 更新时间: 2024-01-13