PHP code example of pe / component-process

1. Go to this page and download the library: Download pe/component-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/ */

    

pe / component-process example snippets




namespace PE\Component\Process;

// Instantiate manager
$manager = new Manager();

// Create process
$process = new Process(function (Process $process) {
    //TODO do some stuff...
});

// Execute process
$manager->fork($process);
$manager->fork($process);
$manager->fork($process);
$manager->fork($process);// <-- this will be ignored because we set max executed processes

// Wait until processes completed
$manager->wait();



namespace PE\Component\Process;

use Psr\Log\NullLogger;

// Define path to pid file, must be writable by php user
$pidPath = sys_get_temp_dir() . '/daemon.pid';

// Instantiate a daemon
$daemon = new Daemon(function () {
    //TODO do some stuff...
}, $pidPath);

// Instantiate logger
$logger = new NullLogger();

// Start execution in background
$daemon->start($logger);

// You can check if daemon is still running by call:
$daemon->isRunning();

// You can break execution by call:
$daemon->stop($logger);