Code Monkey home page Code Monkey logo

spawn's Introduction

Spawn

Spawn - Process Manager for Handling Multiple Processes in PHP 5.4+

Quick Start

Use example.php file to execute test:

// load Spawn
require_once './spawn.bootstrap.php';

try
{
	// set Spawn object
	$spawn = new \Spawn\Manager;

	// turn on debug messages for testing
	$spawn->debug_mode = true;

	// allow 3 processes to run concurrently (default is 3)
	$spawn->max_processes = 3;

	// add test processes
	$spawn->add('php -r "sleep(1); echo \'process 1\';"');
	$spawn->add('php -r "sleep(2); echo \'process 2\';"');
	$spawn->add('php -r "sleep(3); echo \'process 3\';"');
	$spawn->add('php -r "sleep(4); echo \'process 4\';"');
	$spawn->add('php -r "sleep(5); echo \'process 5\';"');

	// start processes
	$spawn->execute();
}
catch(\Exception $ex)
{
	echo $ex->getMessage();
}

Run example.php script using command line (PHP CLI):

# php example.php
Executing command: php -r "sleep(1); echo 'process 1';"
Executing command: php -r "sleep(2); echo 'process 2';"
Executing command: php -r "sleep(3); echo 'process 3';"
process 1
Done: php -r "sleep(1); echo 'process 1';"
Executing command: php -r "sleep(4); echo 'process 4';"
process 2
Done: php -r "sleep(2); echo 'process 2';"
Executing command: php -r "sleep(5); echo 'process 5';"
process 3
Done: php -r "sleep(3); echo 'process 3';"
process 4
Done: php -r "sleep(4); echo 'process 4';"
process 5
Done: php -r "sleep(5); echo 'process 5';"

Spawn Settings

Settings can be customized for script optimization

Debug Mode

Debug mode can be turned on to display helpful debugging messages:

$spawn->debug_mode = true;

Error Log

An error log path can be set to output any process errors to a log, if not set errors will be directly outputted

$spawn->error_log_path = './errors.log';

Maximum Concurrent Processes

The number of concurrent process can be limited using the property below:

$spawn->max_processes = 3;

Step Sleep Time

The step sleep time can be adjusted in milliseconds using the property below, a minimum of 100 milliseconds is required:

$spawn->sleep_milliseconds = 500;

Verbose Option

The verbose option allows for process output messages, setting false will suppress process messages and errors

$spawn->verbose = true;

spawn's People

Contributors

shayanderson avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.