PHP code example of crodas / concurrent-file-writer
1. Go to this page and download the library: Download crodas/concurrent-file-writer 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/ */
crodas / concurrent-file-writer example snippets
use ConcurrentFileWriter\ConcurrentFileWriter;
$x = new ConcurrentFileWriter('/tmp/file.txt');
// This will return TRUE the first time, FALSE if the file is already create and in process and an exception is the file exists and it seems to be finished.
$x->create();
// This calls can happen in parallel (with the same initialization as above).
$x->write( $offset, $content );
$x->write( $offset, $content );
// Only one process can finalize the file writing, it will block.
// Finalize will return TRUE on success FALSE if another process is already doing it.
$x->finalize();