Library for non blocking background jobs in PHP
Install composer in your project:
curl -s https://getcomposer.org/installer | php
Create a composer.json
file in your project root:
{
"require": {
"devbabuind/non-blocking-php": "dev-master"
}
}
Install via composer:
php composer.phar install
Add this line to your application's index.php file:
require 'vendor/autoload.php';
Import the required classes into your namespace:
use DevBabuInd\NonBlockingPHP\Execute;
Instantiate a new Execute:
$execute = new Execute(array('autoMode' => true));
Add some parameters:
$query_params = array('foo'=>'bar');
$folder_protection = array('username' => 'test', 'password' => 'test');
/* sample parameters */
$params = array(
'url' => 'http://www.yourappdomain.com/job.php',
'command' => 'php /folderpathofyourapp/job.php',
'auth' => $folder_protection,
'args' => $query_params
);
Now run the job:
$result = $execute->run($params);
You can get the output:
if ($result) {
echo "Yay! Background call initiated";
} else {
print_r($execute->getError());
}