2017 © Pedro Peláez
 

spryprovider spry-background-process

Provider for Spry Background Processes

image

ggedde/spry-background-process

Provider for Spry Background Processes

  • Saturday, October 21, 2017
  • by ggedde
  • Repository
  • 1 Watchers
  • 0 Stars
  • 30 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

spry-background-process

Provider for Spry Background Processes, (*1)

Dependencies

Background Processes - https://github.com/cocur/background-process, (*2)

Requirements

  • PHP 5.4^
  • PHP with cli
  • function "shell_exec()" available.
  • Spry-Core https://github.com/ggedde/spry-core

Usage

use Spry\SpryProvider\SpryBackgroundProcess;

$process = [
    'controller' => 'Spry\\SpryComponent\\MyController::myMethod',
    'params' => [
        'id' => 123,
        'name' => 'Something'
    ]
];

// Run the Process and return its unix ID
$process_id = SpryBackgroundProcess::create($process);

// Check to see if the process is still running
if(SpryBackgroundProcess::isRunning($process_id))
{
    // It is still running
}
else
{
    // It has finished
}

// Stop a Process by unix ID
SpryBackgroundProcess::stop($process_id);

Unix Process IDs get recycled so it is possible that the same ID may get used for another task. This could present faulty data when checking the to see if the process is still running OR worse you run the "stop" method on the ID, but the ID was for something else like PHP, Apache, Nginx, Etc which could halt your server entirely., (*3)

So a better option would be to verify the process with a Hash of Command and the Time of the command.
* Although this method has not been fully tested on all OS Versions., (*4)

$process = [
    'controller' => 'Spry\\SpryComponent\\MyController::myMethod',
    'hash' => true,
    'params' => [
        'id' => 123,
        'name' => 'Something'
    ]
];

// Run the Process and return its unix ID and Hash
$process_data = SpryBackgroundProcess::create($process);

// Check to see if the process is still running
if(SpryBackgroundProcess::isRunning($process_data['pid'], $process_data['hash']))
{
    // It is still running
}
else
{
    // It has finished
}

// Stop a Process by unix ID and Hash
SpryBackgroundProcess::stopIfIsRunning($process_data['pid'], $process_data['hash']);

The Versions

21/10 2017

dev-master

9999999-dev

Provider for Spry Background Processes

  Sources   Download

MIT

The Requires

 

by Avatar ggedde

28/09 2017

0.9.5

0.9.5.0

Provider for Spry Background Processes

  Sources   Download

MIT

The Requires

 

by Avatar ggedde

27/09 2017

0.9.4

0.9.4.0

Provider for Spry Background Processes

  Sources   Download

MIT

The Requires

 

by Avatar ggedde

27/09 2017

0.9.3

0.9.3.0

Provider for Spry Background Processes

  Sources   Download

MIT

The Requires

 

by Avatar ggedde

20/09 2017

0.9.2

0.9.2.0

Provider for Spry Background Processes

  Sources   Download

MIT

The Requires

 

by Avatar ggedde

18/09 2017

0.9.1

0.9.1.0

Provider for Spry Background Processes

  Sources   Download

MIT

The Requires

 

by Avatar ggedde