1. Go to this page and download the library: Download toolkit/sys-utils 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/ */
toolkit / sys-utils example snippets
use Toolkit\Sys\Proc\ProcTasks;
// ProcTasks::new() // will auto get cpu num as proc num
ProcTasks::new(['procNum' => 2])
->setTaskHandler(function (array $task, array $ctx) {
$pid = $ctx['pid'];
println("worker#{$ctx['id']} [PID:$pid] - handle task, task data", $task);
sleep(random_int(1, 3));
})
->onBeforeCreate(fn($pid, $num) => println("master [PID:$pid] - Will create task process, number:", $num))
->onWorkersCreated(fn($pid, $info) => println("master [PID:$pid] - All task process started,", 'Workers info', $info))
->onWorkerStart(fn($pid, $id) => println("worker#$id started, pid is", $pid))
->onWorkerExit(fn($pid, $id) => println("worker#$id exited, pid is", $pid))
->onCompleted(fn($pid) => println("master [PID:$pid] - all workers exited, tasks run completed"))
->setTasks([
['task1'], // one task
['task2'],
['task3'],
['task4'],
])
->addTask(['task5'])
->run();
bash
php example/proc-tasks.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.