milanowicz / php-thread
适用于GNU/Linux系统的线程库
1.0.1
2022-03-10 15:52 UTC
Requires
- php: ^8.0
Requires (Dev)
- infection/infection: ^0.26
- johnkary/phpunit-speedtrap: ^4.0
- milanowicz/php-testing: ^1.0
- phpstan/phpstan: ^1.4
- phpunit/phpunit: ^9.5
- slevomat/coding-standard: ^7.0
This package is auto-updated.
Last update: 2024-09-07 03:18:46 UTC
README
通过此包控制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