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)361.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 1mo 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 77% 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

3517d 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

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M561](/packages/symfony-maker-bundle)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M81](/packages/symplify-monorepo-builder)[cocur/background-process

Start processes in the background that continue running when the PHP process exists.

2971.9M12](/packages/cocur-background-process)[civicrm/civicrm-core

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

728272.9k17](/packages/civicrm-civicrm-core)[friendsoftypo3/content-blocks

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

96374.6k23](/packages/friendsoftypo3-content-blocks)[nativephp/desktop

NativePHP for Desktop

34020.6k3](/packages/nativephp-desktop)

PHPackages © 2026

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