Skip to content

diversen/background-job

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

background-job

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."

About

Execute a background process with PHP

Topics

Resources

Stars

Watchers

Forks

Packages