PHP code example of cellard / process-manager

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

    

cellard / process-manager example snippets


$pm = new ProcessManager('example');

if ($pm->lock()) {
    // Do your job
 
} else {
    // All threads are engaged
}

$pm = ProcessManager::queue('example');

$lock = ProcessManager::queue('converter')
    ->threads(2)
    ->lock(function(ProcessManager $pm) {
        // Do your job
    
    });

if ( ! $lock) {
    // All threads are engaged
}

$pm = ProcessManager::queue('converter')
    ->threads(2);

if (!$pm->lock()) {
    exit('Too many threads');
}

while (FilesToConvert::getOne() as $filename) {
    if (!$pm->subject($filename)->lock()) {
        // file is converting now by other thread
        continue;
    }
    
    // Your code to convert file here
}

while (FilesToConvert::getOne() as $filename) {
    ProcessManager::queue('converter')
        ->threads(2)
        ->subject($filename)
        ->lock(ProcessManager $pm) use ($filename) {
            // Your code to convert file here
        });
}

ProcessManager::$driver = new \Cellard\ProcessManager\Drivers\FilesystemDriver(/* optional */ $loc_dir);

ProcessManager::$driver = new \Cellard\ProcessManager\Drivers\RedisDriver(/* optional */ $predis_config);

ProcessManager::$prefix = 'your-project-name';

#crontab
* * * * * php example.php
* * * * * php converter.php