PHP code example of acet / reslock

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

    

acet / reslock example snippets


use acet\ResLock;

$contentious_file = 'contentious.file';

$reslock = new ResLock();

// Provide a name for the resource (any string will do - can be a file name, or the name of your cat)
if ($reslock->lock('tiddles')) {

    // resource successfully locked

    $file_contents = file_get_contents($contentious_file);
    $string = "Do something";
    file_put_contents($contentious_file, $string);

    $reslock->unlock();
}

else {
    throw new exception("Unable to lock the resource");
}