PHP code example of kohkimakimoto / background-process

1. Go to this page and download the library: Download kohkimakimoto/background-process library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kohkimakimoto / background-process example snippets


use Kohkimakimoto\BackgroundProcess\BackgroundProcess;

// Creates instance and set command string to run at the background.
$process = new BackgroundProcess("ls -l > /tmp/test.txt");
// Runs command, and it returns immediately.
$process->run();

// Get key identified the process.
$key = $process->getKey();

use Kohkimakimoto\BackgroundProcess\BackgroundProcessManager;

$manager = new BackgroundProcessManager();
$process = $manager->loadProcess($key);

// If a process specified by the key dosen't exist, loadProcess method returns null.
if (!$process) {
  echo "Not working process $key";
} else {
  $meta = $process->getMeta();
  echo $meta['created_at'];   // (ex 2013-01-01 10:00:20
  echo $meta['pid'];          // (ex 1234
}


use Kohkimakimoto\BackgroundProcess\BackgroundProcess;

// Creates instance and set command string to run at the background.
$process = new BackgroundProcess("ls -l > /tmp/test.txt", array(
  'working_directory' => '/path/to/background_process_directroy',
  'key_prefix'        => 'prefix_of_key.',
  'error_log'         => 'your_error.log',
));

/tmp/php/background_process/process.2494951fd9d147bc3e.php

/tmp/php/background_process/process.2494951fd9d147bc3e.json