diversen/background-job

Simple background job creator

1.0.5 2016-05-24 19:23 UTC

This package is auto-updated.

Last update: 2024-12-20 08:27:33 UTC


README

PHP class that executes background jobs (in a very simple way).

Used this answer found on stackoverflow.com:

http://stackoverflow.com/a/45966/464549

You will need unix platform for this to work

Install

composer require diversen/background-job

Usage

cd background-job && php example.php

example.php:

<?php

include_once "bgJob.php"; // Only used if autoloader is not enabled
use diversen\bgJob;

$bg = new bgJob();
$command = "./example.sh";
$bg->execute($command, "output.txt", "pid.txt");

// View pid
echo $bg->pid . "\n";

This executes example.sh:

#!/bin/bash
echo "Hi, I'm sleeping for 5 seconds..."
date
sleep 5
echo "all Done."