Skip to content

Commit 8d65c68

Browse files
committed
open source the project
0 parents  commit 8d65c68

File tree

7 files changed

+544
-0
lines changed

7 files changed

+544
-0
lines changed

.gitignore

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# phpstorm project files
2+
.idea
3+
4+
# netbeans project files
5+
nbproject
6+
7+
# zend studio for eclipse project files
8+
.buildpath
9+
.project
10+
.settings
11+
12+
# windows thumbnail cache
13+
Thumbs.db
14+
15+
# composer vendor dir
16+
vendor
17+
18+
# composer itself is not needed
19+
composer.phar
20+
21+
# composer.lock in applications is ignored since it's automatically created by composer when application is installed
22+
composer.lock
23+
24+
# Mac DS_Store Files
25+
.DS_Store
26+
27+
# phpunit itself is not needed
28+
phpunit.phar
29+
# local phpunit config
30+
phpunit.xml

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Upfor Club
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# ForkMan
2+
> A lightest process manager(inspired by [SimpleFork](https://github.com/SegmentFault/SimpleFork))
3+
4+
## Install
5+
```
6+
$ composer require upfor/forkman
7+
```
8+
9+
## Example
10+
```
11+
<?php
12+
13+
use Upfor\ForkMan\ForkMan;
14+
15+
require 'vendor/autoload.php';
16+
17+
$fm = new ForkMan(2);
18+
$fm->master(function (ForkMan $fm) {
19+
$fm->submit([1, 1000]);
20+
$fm->submit([1001, 2000]);
21+
22+
$fm->wait(3000);
23+
})->slave(function ($params, ForkMan $fm) {
24+
$fm->log($params);
25+
});
26+
27+
```
28+
29+
## License
30+
**ForkMan** is under the [MIT](LICENSE) license.

composer.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "upfor/forkman",
3+
"type": "library",
4+
"description": "A lightest process manager",
5+
"keywords": [
6+
"framework",
7+
"php",
8+
"upfor",
9+
"fork"
10+
],
11+
"homepage": "https://github.com/upfor/forkman",
12+
"license": "MIT",
13+
"authors": [
14+
{
15+
"name": "Upfor Club",
16+
"email": "[email protected]",
17+
"homepage": "https://upfor.club"
18+
},
19+
{
20+
"name": "Shocker Li",
21+
"email": "[email protected]",
22+
"homepage": "http://shockerli.net"
23+
}
24+
],
25+
"require": {
26+
"php": ">=5.5"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"Upfor\\ForkMan\\": "src/"
31+
}
32+
}
33+
}

examples/loop.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
4+
require dirname(__DIR__) . '/src/ForkMan.php';
5+
6+
use Upfor\ForkMan\ForkMan;
7+
8+
$fm = new ForkMan(2);
9+
$fm->master(function (ForkMan $fm) {
10+
while ($fm->loop(1000)) {
11+
$fm->submit('https://api.myjson.com/bins/ladzj', function ($data) {
12+
echo $data, "\n";
13+
});
14+
}
15+
})->slave(function ($url, ForkMan $fm) {
16+
$fm->log($url);
17+
return file_get_contents($url);
18+
});

examples/map-reduce.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
require dirname(__DIR__) . '/src/ForkMan.php';
4+
5+
use Upfor\ForkMan\ForkMan;
6+
7+
$fm = new ForkMan(2);
8+
$fm->master(function (ForkMan $fm) {
9+
$fm->submit([1, 1000]);
10+
$fm->submit([1001, 2000]);
11+
$fm->submit([2001, 3000]);
12+
13+
$fm->wait(3000);
14+
})->slave(function ($params, ForkMan $fm) {
15+
$fm->log($params);
16+
});

0 commit comments

Comments
 (0)