https://github.com/milanowicz/php-thread
Control processes in GNU/Linux systems by PHP
https://github.com/milanowicz/php-thread
php thread thread-library threads
Last synced: 2 months ago
JSON representation
Control processes in GNU/Linux systems by PHP
- Host: GitHub
- URL: https://github.com/milanowicz/php-thread
- Owner: milanowicz
- License: gpl-3.0
- Created: 2022-02-26T21:00:14.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2025-03-08T09:13:54.000Z (2 months ago)
- Last Synced: 2025-03-08T10:20:35.400Z (2 months ago)
- Topics: php, thread, thread-library, threads
- Language: PHP
- Homepage:
- Size: 578 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: ReadMe.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Thread

[](https://dashboard.stryker-mutator.io/reports/github.com/milanowicz/php-thread/master)
[](https://codecov.io/gh/milanowicz/php-thread)





Control processes in GNU/Linux systems by this package for PHP 8.x
## Usage
Install it by Composer
```shell
> composer require milanowicz/php-thread
```Class to control thread for one command
```php
$thread = new Milanowicz\Thread\Threads();
$thread->exec('php scripts/script1.php');
$thread->exec('php scripts/script2.php');
$thread->anyRunning();
$thread->stopAll();
$thread->reset();
```Worker to run commands
```php
$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 ; });
$worker->run(); // Main call to start worker loop$worker->getThread(); // Get current Thread instance
```Singleton to control it everywhere you like
```php
$singleton = new Milanowicz\Thread\ThreadSingleton();
$singleton->exec('php scripts/script1.php');
$singleton->exec('php scripts/script2.php');
$singleton->anyRunning();
$singleton->stopAll();
$singleton->reset
```Worker and Singleton
```php
$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();
```## Development
Run all test suites
```shell
> composer tests
```Run PHP Code Styling
```shell
> composer style
```Run PHPStan to analyze code
```shell
> composer analyze
```Run PHPUnit tests
```shell
> composer test
```Run Mutation tests by Infection
```shell
> composer infection
```## License
[GNU GPL Version 3](http://www.gnu.org/copyleft/gpl.html)