GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - php-toolkit/sys-utils: Useful system helper tool library for PHP

BranchesTags
Open more actions menu

Latest commit

 

History

71 Commits
71 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
example
example
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.php_cs
.php_cs
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
phpunit.xml
phpunit.xml
 
 

Repository files navigation

System Utils

License Php Version Support Latest Stable Version Unit-Tests

Some useful system utils for php

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

Install

composer require toolkit/sys-utils

Usage

ProcTasks

Example:

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:

php example/proc-tasks.php

Output:

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

About

Useful system helper tool library for PHP

Topics

processrun-commandssystem-envsystem-utility

Resources

Readme
MIT license
Activity
Custom properties

Stars

3 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.