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

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

braincrafted/background-process
===============================

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

v0.7(9y ago)2976.1k62[1 issues](https://github.com/cocur/background-process/issues)[5 PRs](https://github.com/cocur/background-process/pulls)1MITPHPPHP &gt;=5.5

Since Apr 24Pushed 4y ago15 watchersCompare

[ Source](https://github.com/cocur/background-process)[ Packagist](https://packagist.org/packages/braincrafted/background-process)[ RSS](/packages/braincrafted-background-process/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (1)Versions (12)Used By (1)

cocur/background-process
========================

[](#cocurbackground-process)

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

[![Latest Stable Version](https://camo.githubusercontent.com/95bfd17382375d12f182288ea7c7722c434bbde2353d121fe4a07a276d6f654c/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f6375722f6261636b67726f756e642d70726f636573732e737667)](https://packagist.org/packages/cocur/background-process)[![Build Status](https://camo.githubusercontent.com/dc9de7c04bc0eb7d6134f8dcb6f698910753476825266967b7627d592afd6173/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f636f6375722f6261636b67726f756e642d70726f636573732e737667)](https://travis-ci.org/cocur/background-process)[![Windows Build status](https://camo.githubusercontent.com/d9cb1fe5dffd87dc0bc46f4759bff7ecf619e2b84ac78b3fad383c4166de1b57/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f6f646d79796e643532327675656631793f7376673d74727565)](https://ci.appveyor.com/project/florianeckerstorfer/background-process)[![Code Coverage](https://camo.githubusercontent.com/ed853e33cbb8ddfaf14e6fe37a69040d27b07b3e7136e54e55b7eb6914098faa/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f6375722f6261636b67726f756e642d70726f636573732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/cocur/background-process/?branch=master)

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

[](#installation)

You can install Cocur\\BackgroundProcess using [Composer](http://getcomposer.org):

```
$ composer require cocur/background-process
```

Usage
-----

[](#usage)

The following example will execute the command `sleep 5` in the background. Thus, if you run the following script either in the browser or in the command line it will finish executing instantly.

```
use Cocur\BackgroundProcess\BackgroundProcess;

$process = new BackgroundProcess('sleep 5');
$process->run();
```

You can retrieve the process ID (PID) of the process and check if it's running:

```
use Cocur\BackgroundProcess\BackgroundProcess;

$process = new BackgroundProcess('sleep 5');
$process->run();

echo sprintf('Crunching numbers in process %d', $process->getPid());
while ($process->isRunning()) {
    echo '.';
    sleep(1);
}
echo "\nDone.\n";
```

If the process runs you can stop it:

```
// ...
if ($process->isRunning()) {
    $process->stop();
}
```

*Please note: If the parent process continues to run while the child process(es) run(s) in the background you should use a more robust solution, for example, the [Symfony Process](https://github.com/symfony/Process) component.*

### Windows Support

[](#windows-support)

Since Version 0.5 Cocur\\BackgroundProcess has basic support for Windows included. However, support is very limited at this time. You can run processes in the background, but it is not possible to direct the output into a file and you can not retrieve the process ID (PID), check if a process is running and stop a running process.

In practice, the following methods will throw an exception if called on a Windows system:

- `Cocur\BackgroundProcess\BackgroundProcess::getPid()`
- `Cocur\BackgroundProcess\BackgroundProcess::isRunning()`
- `Cocur\BackgroundProcess\BackgroundProcess::stop()`

### Create with existing PID

[](#create-with-existing-pid)

If you have a long running process and store its PID in the database you might want to check at a later point (when you don't have the BackgroundProcess object anymore) whether the process is still running and stop the process.

```
use Cocur\BackgroundProcess\BackgroundProcess;

$process = BackgroundProcess::createFromPID($pid);
$process->isRunning(); // -> true
$process->stop();      // -> true
```

Change Log
----------

[](#change-log)

### Version 0.7 (11 February 2017)

[](#version-07-11-february-2017)

- [\#19](https://github.com/cocur/background-process/pull/19) Create `BackgroundProcess` object from PID (by [socieboy](https://github.com/socieboy) and [florianeckerstorfer](https://github.com/florianeckerstorfer))

### Version 0.6 (10 July 2016)

[](#version-06-10-july-2016)

- [\#17](https://github.com/cocur/background-process/pull/17) Add ability to append to file on Unix/Linux-based systems (by [bpolaszek](https://github.com/bpolaszek))

### Version 0.5 (24 October 2015)

[](#version-05-24-october-2015)

- Added basic support for Windows

### Version 0.4 (2 April 2014)

[](#version-04-2-april-2014)

- Moved repository to Cocur organization
- Changed namespace to `Cocur`
- PSR-4 compatible namespace
- [\#3](https://github.com/cocur/background-process/pull/3) Added `BackgroundProcess::stop()` (by florianeckerstorfer)

### Version 0.3 (15 November 2013)

[](#version-03-15-november-2013)

- Changed namespace to `Braincrafted`

Author
------

[](#author)

[**Florian Eckerstorfer**](http://florian.ec)

- [Twitter](http://twitter.com/Florian_)

License
-------

[](#license)

The MIT license applies to **cocur/background-process**. For the full copyright and license information, please view the LICENSE file distributed with this source code.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community26

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~139 days

Recently: every ~119 days

Total

11

Last Release

3376d ago

### Community

Maintainers

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

---

Top Contributors

[![Samyoul](https://avatars.githubusercontent.com/u/5702426?v=4)](https://github.com/Samyoul "Samyoul (3 commits)")[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")[![bpolaszek](https://avatars.githubusercontent.com/u/5569077?v=4)](https://github.com/bpolaszek "bpolaszek (1 commits)")[![mhor](https://avatars.githubusercontent.com/u/4103719?v=4)](https://github.com/mhor "mhor (1 commits)")[![socieboy](https://avatars.githubusercontent.com/u/7442695?v=4)](https://github.com/socieboy "socieboy (1 commits)")[![sponno](https://avatars.githubusercontent.com/u/70642?v=4)](https://github.com/sponno "sponno (1 commits)")

---

Tags

phpprocessunixprocessbackground

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[cocur/background-process

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

2971.9M12](/packages/cocur-background-process)[react/child-process

Event-driven library for executing child processes with ReactPHP.

34076.1M136](/packages/react-child-process)[seld/signal-handler

Simple unix signal handler that silently fails where signals are not supported for easy cross-platform development

18271.3M19](/packages/seld-signal-handler)[phpmentors/workflower

A BPMN 2.0 workflow engine for PHP

70652.9k4](/packages/phpmentors-workflower)[duncan3dc/fork-helper

Simple class to fork processes in PHP and allow multi-threading

73548.0k4](/packages/duncan3dc-fork-helper)[arara/process

Provides a better API to work with processes on Unix-like systems

16861.7k2](/packages/arara-process)

PHPackages © 2026

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