Skip to content

Commit 62bc828

Browse files
committed
init prject
1 parent f6330d5 commit 62bc828

9 files changed

Lines changed: 560 additions & 25 deletions

File tree

.php-cs-fixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
$header = <<<'EOF'
4-
This file is part of inherelab/php-pkg-template.
4+
This file is part of phppkg/taskpm.
55
66
@link https://github.com/inhere
77
@author https://github.com/inhere

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
# php-pkg-template
22

3-
[![License](https://img.shields.io/github/license/inherelab/php-pkg-template.svg?style=flat-square)](LICENSE)
4-
[![Php Version](https://img.shields.io/packagist/php-v/inherelab/php-pkg-template?maxAge=2592000)](https://packagist.org/packages/inherelab/php-pkg-template)
5-
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/inherelab/php-pkg-template)](https://github.com/inherelab/php-pkg-template)
6-
[![Actions Status](https://github.com/inherelab/php-pkg-template/workflows/Unit-Tests/badge.svg)](https://github.com/inherelab/php-pkg-template/actions)
3+
[![License](https://img.shields.io/github/license/phppkg/taskpm.svg?style=flat-square)](LICENSE)
4+
[![Php Version](https://img.shields.io/packagist/php-v/phppkg/taskpm?maxAge=2592000)](https://packagist.org/packages/phppkg/taskpm)
5+
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/phppkg/taskpm)](https://github.com/phppkg/taskpm)
6+
[![Actions Status](https://github.com/phppkg/taskpm/workflows/Unit-Tests/badge.svg)](https://github.com/phppkg/taskpm/actions)
77

8-
TODO: package_description
8+
Run multi tasks by PHP multi process
99

1010
## Install
1111

1212
**composer**
1313

1414
```bash
15-
composer require inherelab/php-pkg-template
15+
composer require phppkg/taskpm
1616
```
1717

1818
## Usage
1919

2020
- github: `use the template` for quick create project
2121
- clone this repository to local
2222
- search `package_description` and replace your package description
23-
- search all `inherelab/php-pkg-template` and replace to your package name.
23+
- search all `phppkg/taskpm` and replace to your package name.
2424
- contains all words like `InhereLab\DemoPkg`
2525
- update `composer.json` contents, field: name, description, require, autoload
2626

27+
## Refers
28+
29+
- https://github.com/upfor/forkman
30+
- https://github.com/SegmentFault/SimpleFork
31+
- https://github.com/huyanping/simple-fork-php
32+
- https://github.com/Arara/Process
33+
- https://github.com/bouiboui/spawn
34+
- https://github.com/symplely/processor
35+
- https://github.com/symplely/coroutine
36+
2737
## License
2838

2939
[MIT](LICENSE)

composer.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "inherelab/php-pkg-template",
3-
"description": "TODO: package description",
2+
"name": "phppkg/taskpm",
3+
"description": "Run multi tasks by PHP multi process",
44
"type": "library",
55
"license": "MIT",
6-
"homepage": "https://github.com/inherelab/php-pkg-template",
6+
"homepage": "https://github.com/phppkg/taskpm",
77
"keywords": [
88
"library",
99
"tool"
@@ -15,18 +15,17 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">7.4.0",
19-
"ext-mbstring": "*",
20-
"toolkit/stdlib":"~1.0"
18+
"php": ">8.0.0",
19+
"toolkit/sys-utils":"~2.0"
2120
},
2221
"autoload": {
2322
"psr-4": {
24-
"InhereLab\\DemoPkg\\": "src/"
23+
"PhpPkg/TaskPM\\": "src/"
2524
}
2625
},
2726
"autoload-dev": {
2827
"psr-4": {
29-
"InhereLab\\DemoPkgTest\\": "test/"
28+
"PhpPkg/TaskPMTest\\": "test/"
3029
}
3130
},
3231
"bin": [

example/demo.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
22

3-
use PhpComLab\CliMarkdown\CliMarkdown;
3+
use PhpPkg\TaskPM\TaskManager;
44

5-
require dirname(__DIR__) . '/vendor/autoload.php';
5+
require dirname(__DIR__) . '/test/bootstrap.php';
66

7-
$contents = file_get_contents(dirname(__DIR__) . '/README.md');
8-
$praser = new CliMarkdown;
7+
TaskManager::new()
8+
->onMaster(function () {
99

10-
$rendered = $praser->render($contents);
11-
12-
echo $rendered;
10+
})
11+
->onWorker(function () {
1312

13+
})
14+
->wait();

example/map-reduce.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use PhpPkg\TaskPM\TaskManager;
4+
5+
require dirname(__DIR__) . '/test/bootstrap.php';
6+
7+
// run: php example/map-reduce.php
8+
TaskManager::new()
9+
->onMaster(function (TaskManager $mgr) {
10+
$mgr->submit([1, 1000]);
11+
12+
sleep(3);
13+
$mgr->submit([1001, 2000]);
14+
15+
sleep(3);
16+
$mgr->submit([2001, 3000], function ($data, TaskManager $mgr) {
17+
$mgr->log('submit 3', ['ctx' => $data]);
18+
19+
sleep(3);
20+
$mgr->submit([3001, 4000]);
21+
});
22+
23+
// $mgr->wait(3000);
24+
})
25+
->onWorker(function ($params, TaskManager $mgr) {
26+
// slave process's callback cannot print anything, print log please use $fm->log()
27+
$mgr->log('on slave', $params);
28+
return $params;
29+
})
30+
->wait(3000);

src/.keep

Whitespace-only changes.

src/TaskContext.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PhpPkg\TaskPM;
4+
5+
class TaskContext
6+
{
7+
8+
}

0 commit comments

Comments
 (0)