milanowicz/php-thread

适用于GNU/Linux系统的线程库

安装: 4

依赖: 0

建议者: 0

安全性: 0

星星: 2

关注者: 2

分支: 0

开放问题: 5

类型:php-library

1.0.1 2022-03-10 15:52 UTC

README

Test Mutation testing codecov

通过此包控制GNU/Linux系统中的PHP 8.x进程

使用方法

使用Composer安装

> composer require milanowicz/php-thread

控制单个命令的线程类

$thread = new Milanowicz\Thread\Threads();
$thread->exec('php scripts/script1.php');
$thread->exec('php scripts/script2.php');
$thread->anyRunning();
$thread->stopAll();
$thread->reset();

运行命令的工作者

$worker = new Milanowicz\Thread\Worker([
    'command' => '/bin/sleep 2',
    'execMaxCounter' => 10, // How many would you execute?
    'maxWorkers' => 2, // How process(es) should be started? 
    'maxExecutionTime' => 120, // Seconds to run php script
    'memoryLimit' => '32M', // Maximum for php memory limit
    'workerDelayStart' => 1, // Delay for starting processes after each other
    'workerRunSleep' => 2, // Sleep to check again if enough processes are running
]);
$worker->setCheckDispatcher(function () { return <bool>; });
$worker->run(); // Main call to start worker loop

$worker->getThread(); // Get current Thread instance

在您喜欢的任何地方控制的单例

$singleton = new Milanowicz\Thread\ThreadSingleton();
$singleton->exec('php scripts/script1.php');
$singleton->exec('php scripts/script2.php');
$singleton->anyRunning();
$singleton->stopAll();
$singleton->reset

工作者和单例

$worker = new Milanowicz\Thread\Worker([
    'command' => '/bin/sleep 20',
    'execMaxCounter' => 10, // How many would you execute?
    'maxWorkers' => 2, // How process(es) should be started?
], new Milanowicz\Thread\ThreadSingleton());
$worker->run();

开发

运行所有测试套件

> composer tests

运行PHP CS Fixer进行代码格式化

> composer style

运行PHPStan进行分析

> composer anlayze

运行PHPUnit测试

> composer test

通过Infection运行突变测试

> composer infection

许可证

GNU GPL版本3