1. Go to this page and download the library: Download icy8/process library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
icy8 / process example snippets
use icy8\process\Worker;
$handle = new Worker();
$handle->total = 2;// 需要运行的进程数
// $handle->max = 10;// 允许同一时间打开的进程数上限 0为无上限;通常建议设定一个大于零的数值
$handle->run(function ($worker) {
// 闭包里是你的业务代码
while (1) {
var_dump(time());
sleep(1);
}
});
use icy8\process\Worker;
$handle = new Worker();
$processes = [
function () {
while (1) {
var_dump('process 1');
sleep(1);
}
},
function () {
while (1) {
var_dump('process 2');
sleep(1);
}
},
function () {
while (1) {
var_dump('process 3');
sleep(1);
}
},
function () {
while (1) {
var_dump('process 4');
sleep(1);
}
},
];
// 此时你不再需要手动配置$handle->total属性
$handle->run($processes);
use icy8\process\Daemon;
$daemo = new Daemon();
$daemon->run(function () {
sleep(10);
});