PHP code example of deepeloper / lib-process

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

    

deepeloper / lib-process example snippets


use deepeloper\Lib\Process\Lock;
use deepeloper\Lib\Process\Lock\Storage;

try {
    $lock = new Lock(
        Storage::getLayer("Filesystem", ['path' => "path/to/lock"]),
        60 * 5, // 5 minutes
        true, // Destroy previous lock, false by default
        // "...", // custom lock id
    );
} catch (RuntimeException $e) {
    switch ($e->getCode()) {
        case Lock::EXISTING_IS_VALID:
            // Previous lock is valid, interrupt process.
            die;
        default:
            throw $e;
    }
}

// Long time loop
while (true) {
    // ...
    try {
        $lock->update(true); // true to call \set_time_limit(), false by default
    } catch (RuntimeException $e) {
        // Lock was destroyed by another instance of the daemon
    }
}