PHP code example of redbitcz / utils

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

    

redbitcz / utils example snippets


    $locker = new Locker(__DIR__, 'example', Locker::NON_BLOCKING);
    
    try {
        $locker->lock();
        
        // ... exclusive operation
        
        $locker->unlock();
    }
    catch (LockObtainException $e) {
        die('Error: Another process is alreasy processing that stuff');
    }

    $locker = new Locker(__DIR__, 'example', Locker::BLOCKING);
    
    $locker->lock(); // concurrent process will be wait here to release previous lock
    
    // ... exclusive operation
    
    $locker->unlock();

$logger->info("Processing message: $messageId");

$messageLogger = $logger->section($messageId);
$messageLogger->info('Open');

function parse(LoggerInterface $parserLogger) {
    $parserLogger->info('Parsing...');
    // ...
    $parserLogger->info('Parsing OK');
}

parse($messageLogger->section('parser'));

$messageLogger->info('Save');

$logger->info('Done');

while(true) {
    $job = $worker->waitToJob();
    
    ProcessTerminationLock::lock(); // Lock termination to prevent break job processing
    
    //... long job processing  

    ProcessTerminationLock::unlock(); // Unlock
}

$variations = BitwiseVariator::create(0b1011)->variate();

$variations = BitwiseVariator::create(0b1011)->must(0b0010)->variate();

$variations = BitwiseVariator::create(0b1011)->mustNot(0b0010)->variate();