{"id":28539015,"url":"https://github.com/cocur/background-process","last_synced_at":"2025-07-08T10:32:42.191Z","repository":{"id":8201939,"uuid":"9634198","full_name":"cocur/background-process","owner":"cocur","description":"Start processes in the background that continue running when the PHP process exists.","archived":false,"fork":false,"pushed_at":"2022-04-06T05:46:38.000Z","size":49,"stargazers_count":297,"open_issues_count":11,"forks_count":61,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-06-18T14:43:12.398Z","etag":null,"topics":["php","process"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Pomax/Font.js","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cocur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-23T21:57:14.000Z","updated_at":"2025-06-11T07:22:04.000Z","dependencies_parsed_at":"2022-08-21T08:50:19.261Z","dependency_job_id":null,"html_url":"https://github.com/cocur/background-process","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/cocur/background-process","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocur%2Fbackground-process","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocur%2Fbackground-process/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocur%2Fbackground-process/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocur%2Fbackground-process/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cocur","download_url":"https://codeload.github.com/cocur/background-process/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocur%2Fbackground-process/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261018649,"owners_count":23097936,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","process"],"created_at":"2025-06-09T18:30:26.367Z","updated_at":"2025-07-08T10:32:42.183Z","avatar_url":"https://github.com/cocur.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"cocur/background-process\n========================\n\n\u003e Start processes in the background that continue running when the PHP process exists.\n\n[![Latest Stable Version](http://img.shields.io/packagist/v/cocur/background-process.svg)](https://packagist.org/packages/cocur/background-process)\n[![Build Status](http://img.shields.io/travis/cocur/background-process.svg)](https://travis-ci.org/cocur/background-process)\n[![Windows Build status](https://ci.appveyor.com/api/projects/status/odmyynd522vuef1y?svg=true)](https://ci.appveyor.com/project/florianeckerstorfer/background-process)\n[![Code Coverage](https://scrutinizer-ci.com/g/cocur/background-process/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/cocur/background-process/?branch=master)\n\n\nInstallation\n------------\n\nYou can install Cocur\\BackgroundProcess using [Composer](http://getcomposer.org):\n\n```shell\n$ composer require cocur/background-process\n```\n\n\nUsage\n-----\n\nThe following example will execute the command `sleep 5` in the background. Thus, if you run the following script \neither in the browser or in the command line it will finish executing instantly.\n\n```php\nuse Cocur\\BackgroundProcess\\BackgroundProcess;\n\n$process = new BackgroundProcess('sleep 5');\n$process-\u003erun();\n```\n\nYou can retrieve the process ID (PID) of the process and check if it's running:\n\n```php\nuse Cocur\\BackgroundProcess\\BackgroundProcess;\n\n$process = new BackgroundProcess('sleep 5');\n$process-\u003erun();\n\necho sprintf('Crunching numbers in process %d', $process-\u003egetPid());\nwhile ($process-\u003eisRunning()) {\n    echo '.';\n    sleep(1);\n}\necho \"\\nDone.\\n\";\n```\n\nIf the process runs you can stop it:\n\n```php\n// ...\nif ($process-\u003eisRunning()) {\n    $process-\u003estop();\n}\n```\n\n*Please note: If the parent process continues to run while the child process(es) run(s) in the background you should \nuse a more robust solution, for example, the [Symfony Process](https://github.com/symfony/Process) component.*\n\n### Windows Support\n\nSince Version 0.5 Cocur\\BackgroundProcess has basic support for Windows included. However, support is very limited at\nthis time. You can run processes in the background, but it is not possible to direct the output into a file and you\ncan not retrieve the process ID (PID), check if a process is running and stop a running process.\n\nIn practice, the following methods will throw an exception if called on a Windows system:\n\n- `Cocur\\BackgroundProcess\\BackgroundProcess::getPid()`\n- `Cocur\\BackgroundProcess\\BackgroundProcess::isRunning()`\n- `Cocur\\BackgroundProcess\\BackgroundProcess::stop()`\n\n### Create with existing PID\n\nIf 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.\n\n```php\nuse Cocur\\BackgroundProcess\\BackgroundProcess;\n\n$process = BackgroundProcess::createFromPID($pid);\n$process-\u003eisRunning(); // -\u003e true\n$process-\u003estop();      // -\u003e true\n```\n\nChange Log\n----------\n\n### Version 0.7 (11 February 2017)\n\n- [#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))\n\n### Version 0.6 (10 July 2016)\n\n- [#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))\n\n### Version 0.5 (24 October 2015)\n\n- Added basic support for Windows\n\n### Version 0.4 (2 April 2014)\n\n- Moved repository to Cocur organization\n- Changed namespace to `Cocur`\n- PSR-4 compatible namespace\n- [#3](https://github.com/cocur/background-process/pull/3) Added `BackgroundProcess::stop()` (by florianeckerstorfer)\n\n### Version 0.3 (15 November 2013)\n\n- Changed namespace to `Braincrafted`\n\n\nAuthor\n------\n\n[**Florian Eckerstorfer**](http://florian.ec)\n\n- [Twitter](http://twitter.com/Florian_)\n\n\nLicense\n-------\n\nThe MIT license applies to **cocur/background-process**. For the full copyright and license information, please view the LICENSE file distributed with this source code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcocur%2Fbackground-process","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcocur%2Fbackground-process","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcocur%2Fbackground-process/lists"}