php-strict/script-runner

Class for running PHP CLI script in several separate processes.

dev-master 2024-06-03 12:11 UTC

This package is auto-updated.

Last update: 2024-11-03 13:27:06 UTC


README

Software License Build Status codecov Codacy Badge

Class for running PHP CLI script in several separate processes.

Requirements

  • PHP >= 7.1

Install

Use class as standalone:

require 'ScriptRunner.php';
use PhpStrict\ScriptRunner\ScriptRunner;

Install with Composer:

composer require php-strict/script-runner

Usage

use PhpStrict\ScriptRunner\ScriptRunner;

//params: path_to_script, processes count (if omitted then system CPU cores count will be used)
$sr = new ScriptRunner('script.php', 4);
$sr->run();

May be used with CooperativeWorker to split one sequential process into several separated processes and keep them from collisions and making the same job twice. For eaxample it is possible to convert process of parsing log files from cycle (where log files parsing one-by-one) into several separated processes where each process take job from common temporary storage (queue).

Tests

To execute the test suite, you'll need Codeception.

vendor/bin/codecept run