2017 © Pedro Peláez
 

library sys-utils

some system tool library of the php

image

toolkit/sys-utils

some system tool library of the php

  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 860 % Grown

The README.md

System Utils

License Php Version Support Latest Stable Version Unit-Tests, (*1)

Some useful system utils for php, (*2)

  • exec system command
  • simple process usage
  • php env info
  • error and exception info

Install

composer require toolkit/sys-utils

Usage

ProcTasks

Example:, (*3)

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();

Run:, (*4)

php example/proc-tasks.php

Output:, (*5)

master [PID:49731] - Will create task process, number: 2
master [PID:49731] - All task process started, Workers info {"49732":{"id":0,"pid":49732,"startAt":1639245860},"49733":{"id":1,"pid":49733,"startAt":1639245860}}
worker#0 started, pid is 49732
worker#0 [PID:49732] - handle task, task data ["task1"]
worker#1 started, pid is 49733
worker#1 [PID:49733] - handle task, task data ["task4"]
worker#1 [PID:49733] - handle task, task data ["task5"]
worker#0 [PID:49732] - handle task, task data ["task2"]
worker#1 exited, pid is 49733
worker#0 [PID:49732] - handle task, task data ["task3"]
worker#0 exited, pid is 49732
master [PID:49731] - all workers exited, tasks run completed

License

MIT, (*6)

The Versions

07/05 2018

dev-master

9999999-dev https://github.com/php-toolkit/sys-utils

some system tool library of the php

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

php library tool

07/05 2018

v1.0.4

1.0.4.0 https://github.com/php-toolkit/sys-utils

some system tool library of the php

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

php library tool

06/05 2018

v1.0.3

1.0.3.0 https://github.com/php-toolkit/sys-utils

some system tool library of the php

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

php library tool

30/04 2018

v1.0.2

1.0.2.0 https://github.com/php-toolkit/sys-utils

some system tool library of the php

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

php library tool

08/02 2018

v1.0.1

1.0.1.0 https://github.com/php-mylib/sys-utils

some system tool library of the php

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

php library tool

30/01 2018

v1.0.0

1.0.0.0 https://github.com/php-mylib/sys-utils

some system tool library of the php

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

php library tool