PHPackages                             kohkimakimoto/background-process - 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. kohkimakimoto/background-process

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

kohkimakimoto/background-process
================================

A minimum library to run background processes asynchronously.

v1.2.0(9y ago)351.4k7Apache License 2.0PHPPHP &gt;=5.3.0

Since Aug 13Pushed 9y ago3 watchersCompare

[ Source](https://github.com/kohkimakimoto/BackgroundProcess)[ Packagist](https://packagist.org/packages/kohkimakimoto/background-process)[ Docs](https://github.com/kohkimakimoto/BackgroundProcess)[ RSS](/packages/kohkimakimoto-background-process/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (3)Versions (5)Used By (0)

BackgroundProcess
=================

[](#backgroundprocess)

[![Build Status](https://camo.githubusercontent.com/96934687b279ae10ff713860fbbd478776d70a0655d3acb765d35d1633508fe4/68747470733a2f2f7472617669732d63692e6f72672f6b6f686b696d616b696d6f746f2f4261636b67726f756e6450726f636573732e706e67)](https://travis-ci.org/kohkimakimoto/BackgroundProcess)[![Coverage Status](https://camo.githubusercontent.com/2c993ce5097dcbdfdbc6df1c7144a93eac6d2fd66d88884b6f727bc11706a949/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6b6f686b696d616b696d6f746f2f4261636b67726f756e6450726f636573732f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/kohkimakimoto/BackgroundProcess?branch=master)

BackgroundProcess is a PHP Library to run background processes asynchronously on your system.

How it works
------------

[](#how-it-works)

[![20130812192611](https://camo.githubusercontent.com/f526dffe5124dfc60379b9a810204d9fe1fe8266048c494915aeb2c89611dd10/687474703a2f2f696d672e662e686174656e612e6e652e6a702f696d616765732f666f746f6c6966652f6b2f6b6f686b696d616b696d6f746f2f32303133303831322f32303133303831323139323631312e706e67)](http://f.hatena.ne.jp/kohkimakimoto/20130812192611)

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.

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**.

**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.

```
/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

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

```

The executable PHP file and JSON meta data file have same name without extentions.

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

Installation
------------

[](#installation)

User composer installation with below `composer.json`.

```
{
  "require": {
    "kohkimakimoto/background-process": "1.1.*"
  }
}
```

And runs Composer install command.

```
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install

```

Usage
-----

[](#usage)

The following code runs a command on the background.

```
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.

```
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.

```
/tmp/php/background_process/err.log

```

Configuration Options
---------------------

[](#configuration-options)

You can use configuration options to change behavior of BackgroundProcess.

```
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
-------

[](#license)

Apache License 2.0

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 92.2% 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 ~378 days

Total

4

Last Release

3569d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/232e612dbf32e70978372a2249e28dd037f75eadafc547913375708571c65f9a?d=identicon)[kohkimakimoto](/maintainers/kohkimakimoto)

---

Top Contributors

[![kohkimakimoto](https://avatars.githubusercontent.com/u/761462?v=4)](https://github.com/kohkimakimoto "kohkimakimoto (71 commits)")[![garagesocial](https://avatars.githubusercontent.com/u/2416014?v=4)](https://github.com/garagesocial "garagesocial (2 commits)")[![kawahara](https://avatars.githubusercontent.com/u/90656?v=4)](https://github.com/kawahara "kawahara (2 commits)")[![Ema4rl](https://avatars.githubusercontent.com/u/2991736?v=4)](https://github.com/Ema4rl "Ema4rl (1 commits)")[![k-holy](https://avatars.githubusercontent.com/u/67330?v=4)](https://github.com/k-holy "k-holy (1 commits)")

---

Tags

processbackground

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kohkimakimoto-background-process/health.svg)

```
[![Health](https://phpackages.com/badges/kohkimakimoto-background-process/health.svg)](https://phpackages.com/packages/kohkimakimoto-background-process)
```

###  Alternatives

[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k245.4M24.0k](/packages/friendsofphp-php-cs-fixer)[symfony/framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework

3.6k246.0M11.1k](/packages/symfony-framework-bundle)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

101466.4k45](/packages/friendsoftypo3-content-blocks)[civicrm/civicrm-core

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

751284.3k37](/packages/civicrm-civicrm-core)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5275.7M110](/packages/symplify-monorepo-builder)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

53675.5k16](/packages/solspace-craft-freeform)

PHPackages © 2026

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