orkestra/daemon

Run PHP scripts as a background daemon

1.0.0 2012-12-31 22:06 UTC

This package is not auto-updated.

Last update: 2024-04-13 10:03:58 UTC


README

Build Status

Daemonize your PHP scripts to accomplish work in the background.

Note: This library requires that you install the Process Control and POSIX extensions.

Installation

The easiest way to add orkestra-common to your project is using composer.

Add orkestra-common to your composer.json file:

{
    "require": {
        "orkestra/daemon": "dev-master"
    }
}

Then run composer install or composer update.

Usage

Spawning a new worker process using pcntl_exec:

<?php

require __DIR__ . '/vendor/autoload.php';

use Orkestra\Daemon\Daemon;
use Orkestra\Daemon\Worker\PcntlWorker;

$daemon = new Daemon();
$daemon->addWorker(new PcntlWorker('/path/to/executable', array('--arg=value')));

$daemon->execute();

Spawning a worker processing using a Symfony Process:

<?php

require __DIR__ . '/vendor/autoload.php';

use Orkestra\Daemon\Daemon;
use Orkestra\Daemon\Worker\ProcessWorker;
use Symfony\Component\Process\Process;

$process = new Process('/path/to/executable --arg=value');

$daemon = new Daemon();
$daemon->addWorker(new ProcessWorker($process));

$daemon->execute();