2017 © Pedro Peláez
 

library background-process

A minimum library to run background processes asynchronously.

image

kohkimakimoto/background-process

A minimum library to run background processes asynchronously.

  • Wednesday, September 21, 2016
  • by kohkimakimoto
  • Repository
  • 4 Watchers
  • 36 Stars
  • 1,264 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

BackgroundProcess

Build Status Coverage Status, (*1)

BackgroundProcess is a PHP Library to run background processes asynchronously on your system., (*2)

How it works

20130812192611, (*3)

BackgroundProcess is simple. So it doesn't need any specific datastores such as RDBMS. And dosen't use somthing like a queue and daemon process., (*4)

When BackgroundProcess runs a process on the background, It creates two special files. One of them is an Executable PHP file. Another one is a JSON meta data file., (*5)

Executable PHP file is a PHP file executed by BackgroundProcess. It includes the command to run specified by you. It also has some initialization and finalization code. At default, this file name is like the following., (*6)

/tmp/php/background_process/process.2494951fd9d147bc3e.php

JSON meta data file is a json formmated file. it's created at the preprocess in the Executable PHP file. It includes process id and created timestamp. It is used to inspect background process statuses through BackgroundProcessManager Class API. At default, this file name is like the following, (*7)

/tmp/php/background_process/process.2494951fd9d147bc3e.json

The executable PHP file and JSON meta data file have same name without extentions., (*8)

These two files are automatically deleted at the end of the processing. Therefore, you generally don't need to manipulate them., (*9)

Installation

User composer installation with below composer.json., (*10)

``` json { "require": { "kohkimakimoto/background-process": "1.1.*" } }, (*11)


And runs Composer install command.

$ curl -s http://getcomposer.org/installer | php $ php composer.phar install, (*12)


## Usage The following code runs a command on the background. ```php use Kohkimakimoto\BackgroundProcess\BackgroundProcess; // Creates instance and set command string to run at the background. $process = new BackgroundProcess("ls -l > /tmp/test.txt"); // Runs command, and it returns immediately. $process->run(); // Get key identified the process. $key = $process->getKey();

The following code inspects the background process., (*13)

use Kohkimakimoto\BackgroundProcess\BackgroundProcessManager;

$manager = new BackgroundProcessManager();
$process = $manager->loadProcess($key);

// If a process specified by the key dosen't exist, loadProcess method returns null.
if (!$process) {
  echo "Not working process $key";
} else {
  $meta = $process->getMeta();
  echo $meta['created_at'];   // (ex 2013-01-01 10:00:20
  echo $meta['pid'];          // (ex 1234
}

If your command raises error, BackgroundProcess writes logs to error log file., (*14)

/tmp/php/background_process/err.log

Configuration Options

You can use configuration options to change behavior of BackgroundProcess., (*15)

use Kohkimakimoto\BackgroundProcess\BackgroundProcess;

// Creates instance and set command string to run at the background.
$process = new BackgroundProcess("ls -l > /tmp/test.txt", array(
  'working_directory' => '/path/to/background_process_directroy',
  'key_prefix'        => 'prefix_of_key.',
  'error_log'         => 'your_error.log',
));

License

Apache License 2.0, (*16)

The Versions

21/09 2016

dev-master

9999999-dev https://github.com/kohkimakimoto/BackgroundProcess

A minimum library to run background processes asynchronously.

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

process background

21/09 2016

v1.2.0

1.2.0.0 https://github.com/kohkimakimoto/BackgroundProcess

A minimum library to run background processes asynchronously.

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

process background

15/08 2013

v1.1.0

1.1.0.0 https://github.com/kohkimakimoto/BackgroundProcess

A minimum library to run background processes asynchronously.

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

process background

13/08 2013

v1.0.1

1.0.1.0 https://github.com/kohkimakimoto/BackgroundProcess

A minimum library to run background processes asynchronously.

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

process background

13/08 2013

v1.0.0

1.0.0.0 https://github.com/kohkimakimoto/BackgroundProcess

A minimum library to run background processes asynchronously.

  Sources   Download

Apache License 2.0

The Requires

 

The Development Requires

process background