PHPackages                             mwstake/mediawiki-component-processmanager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mwstake/mediawiki-component-processmanager

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mwstake/mediawiki-component-processmanager
==========================================

Provides a management system for background processes

5.0.2(yesterday)120.7k↓12.1%1[2 issues](https://github.com/hallowelt/mwstake-mediawiki-component-processmanager/issues)1GPL-3.0-onlyPHPCI passing

Since Feb 9Pushed 1mo ago6 watchersCompare

[ Source](https://github.com/hallowelt/mwstake-mediawiki-component-processmanager)[ Packagist](https://packagist.org/packages/mwstake/mediawiki-component-processmanager)[ RSS](/packages/mwstake-mediawiki-component-processmanager/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (34)Versions (48)Used By (1)

Process Manager
===============

[](#process-manager)

This library allows you to create async background processes, that can be accessed later from anywhere, to check the progress and retrieve output. When you start the process it will be enqueue, and wait for the processRunner to execute it.

Compatibility
-------------

[](#compatibility)

- `5.0.x` -&gt; MediaWiki 1.43
- `4.0.x` -&gt; MediaWiki 1.43
- `3.0.x` -&gt; MediaWiki 1.43
- `3.0.x` -&gt; MediaWiki 1.39
- `1.0.x` -&gt; MediaWiki 1.35

Usage
=====

[](#usage)

Require this component in the `composer.json` of your extension:

```
{
	"require": {
		"mwstake/mediawiki-component-processmanager": "~5"
	}
}
```

Process works based on steps provided to it, it will execute steps sequentialy, passing output data from one step as an input for the next, until the end. Last step will return its output as the output of the whole process.

Steps are defined as `ObjectFactory` specs. Object produced from such specs must be instance of `MWStake\MediaWiki\Component\ProcessManager\IProcessStep`.

Sample step
-----------

[](#sample-step)

```
class Foo implements IProcessStep {

	/** @var ILoadBalancer */
	private $lb;
	/** @var string */
	private $name;

	public function __construct( ILoadBalancer $lb, $name ) {
		$this->lb = $lb;
		$this->name = $name;
	}

	public function execute( $data = [] ): array  {
	// Add "_bar" to the name passed as the argument in the spec and return it
		$name = $this->name . '_bar';

		// some lenghty code

		return [ 'modifiedName' => $name ];
	}
}
```

Creating process
----------------

[](#creating-process)

```
// Create process that has a single step, Foo, defined above
// new ManagerProcess( array $steps, int $timeout );
$process = new ManagedProcess( [
	'foo-step' => [
		'class' => Foo::class,
		'args' => [ 'Bar-name' ],
		'services' => [ 'DBLoadBalancer' ]
	]
], 300 );

$processManager = MediaWikiServices::getInstance()->getService( 'ProcessManager' );

// ProcessManager::startProcess() returns unique process ID that is required
// later on to check on the process state
echo $processManager->startProcess( $process );
// 1211a33123aae2baa6ed1d9a1846da9d
```

Checking process status
-----------------------

[](#checking-process-status)

Once the process is started using the procedure above, and we obtain the process id, we can check on its status anytime, from anywhere, even from different process then the one that started the process

```
$processManager = MediaWikiServices::getInstance()->getService( 'ProcessManager' );
echo $processManager->getProcessInfo( $pid );
// Returns JSON
{
	"pid": "1211a33123aae2baa6ed1d9a1846da9d",
	"started_at": "20220209125814",
	"status": "finished",
	"output": { /*JSON-encoded string of whatever the last step returned as output*/ }
}
```

In case of an error, response will contain status `error`, and show Exception message and callstack.

Interrupting processes
----------------------

[](#interrupting-processes)

Sometimes, we want to pause between steps, and re-evaluate data returned.

This can be achieved if step implements `MWStake\MediaWiki\Component\ProcessManager\InterruptingProcessStep` instead of `MWStake\MediaWiki\Component\ProcessManager\IProcessStep`. In case process comes across an instance of this interface, it will pause the processing and report back data that was returned from the step.

To continue the process, you must call `$processManager->proceed( $pid, $data )`. In this case, `$pid` is the ID of the paused process, and `$data` is any modified data to be passed to the next step. This data will be merged with data returned from previous step (the one that paused the process). This call will return the PID of the process, which should be the same as the one passed (same process continues).

Executing steps synchronously
-----------------------------

[](#executing-steps-synchronously)

This is a spin-off of this component functionality. It allows you to execute steps synchronously, without the need to start a process.

```
$executor = new \MWStake\MediaWiki\Component\ProcessManager\StepExecutor(
MediaWikiServices::getInstance()->getObjectNameUtils()
);
// Optional, if all necessary data is passed in the spec, omit this
$data = [
    'input' => 'data for the first step'
];

$executor->execute( [
    'foo-step' => [
        'class' => Foo::class,
        'args' => [
            $someArg1,
            $someArg2
        ]
    ],
    'bar-step' => [
        'class' => Bar::class,
        'args' => [
            $someArg1,
            $someArg3,
            $someArg4
        ]
    ]
], $data );
```

Notes
-----

[](#notes)

- This component requires an DB table, so `update.php` will be necessary

Setup
-----

[](#setup)

This mechanism has the following main parts:

- `ProcessManager` - a service that manages processes, and allows to start processes, check on their status
- `processRunner.php` - script that retrieves processes from the queue and executes them. This is a long-running script that should be started as a background process
- `processExecution.php` - script that actually runs individual processes. This is a short-lived script and is alive only for the durarion of single process execution

### Setting up processRunner.php

[](#setting-up-processrunnerphp)

Script `processRunner.php` should be started by a crontab. There are two modes of operation:

- executing processes that are currently in the queue
- always running and waiting for new processes to be added to the queue This is the same operation as `runJobs.php` in MediaWiki core.

Parameters:

- first param should be the full path to the `Mainetenance.php` file in MediaWiki core. This is due to this being a component, which does not have a dedicated place in the codebase structure, and can be installed anywhere.
- `--wait` - wait for new processes to be added to the queue. In this mode, script will create a lock file, that will prevent other runners to be started. This is useful when you want to have only one runner running at a time. In case it crashes or is otherwise killed, the lock file will be removed and other runners will be able to start.
- `--max-jobs` - maximum number of processes to execute in one run. This is useful when you want to limit the number of processes.
- `--script-args` - arguments to be passed to `processExecution.php` script. Avoid using if not sure what you are doing.

Crontab example: Should be executed as either the webserver user or root.

```
* * * * * /usr/bin/php /var/www/html/mw/vendor/mwstake/mediawiki-component-processmanager/maintenance/processRunner.php /var/www/html/mw/maintenance/Maintenance.php --wait'

```

\*\* When `--wait` is specified, `--max-processes` has no effect\*\*

### Logging

[](#logging)

Normally, runner logs into `ProcessRunner` channel of debug log mechanism, but it might also be useful to capture output of the script directly (in crontab line) and pipe that into some log, so we can catch any errors in the runner itself.

Consirederations that were taken in implementation
--------------------------------------------------

[](#consirederations-that-were-taken-in-implementation)

This is not an idea way to set up background processing, but we have taken following considerations into account:

- we want to have a parent for all processes, so they dont end up as zombies, and we can capture any output of them
- we do NOT want to need to setup any separate services on machines, like Redis, RabbitMQ, etc. Ideally, no additional setup would be required, but crontab line is necessary.
- we do NOT want to wait for crontab to execute the process, we want to be able to start it immediately, therefore we have the `--wait` parameter
- it has to work on both Linux and Windows

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance76

Regular maintenance activity

Popularity29

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 58.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~39 days

Recently: every ~24 days

Total

42

Last Release

1d ago

Major Versions

2.0.x-dev → 3.0.02024-07-19

3.1.2 → 4.0.02025-10-07

3.0.4 → 4.0.12025-10-08

3.1.3 → 4.0.22025-10-09

3.1.4 → 5.0.02026-04-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/e39dfe9d3120de240053c4283e905254e8774d3278da25ad79974a8742c55192?d=identicon)[osnard](/maintainers/osnard)

![](https://www.gravatar.com/avatar/161c38b5448b71865cf0652b6974ed489dd3683b5d6e1814973cea6cb66c8f1d?d=identicon)[dsavuljesku](/maintainers/dsavuljesku)

---

Top Contributors

[![it-spiderman](https://avatars.githubusercontent.com/u/13665198?v=4)](https://github.com/it-spiderman "it-spiderman (63 commits)")[![osnard](https://avatars.githubusercontent.com/u/1201528?v=4)](https://github.com/osnard "osnard (14 commits)")[![HamishSlater](https://avatars.githubusercontent.com/u/26261210?v=4)](https://github.com/HamishSlater "HamishSlater (13 commits)")[![bluespice-github-bot](https://avatars.githubusercontent.com/u/33830316?v=4)](https://github.com/bluespice-github-bot "bluespice-github-bot (10 commits)")[![Jonty16117](https://avatars.githubusercontent.com/u/24632214?v=4)](https://github.com/Jonty16117 "Jonty16117 (7 commits)")

### Embed Badge

![Health badge](/badges/mwstake-mediawiki-component-processmanager/health.svg)

```
[![Health](https://phpackages.com/badges/mwstake-mediawiki-component-processmanager/health.svg)](https://phpackages.com/packages/mwstake-mediawiki-component-processmanager)
```

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.5k196.2M3.1k](/packages/composer-composer)[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k251.2M25.2k](/packages/friendsofphp-php-cs-fixer)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.1k17.8k](/packages/prestashop-prestashop)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
