Download the PHP package fab2s/filelock without Composer

On this page you can find all versions of the php package fab2s/filelock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package filelock

FileLock

Build Status

A fluent Helper to properly handle file locking based on flock().

FileLock offers two locking strategies and several options. Just like flock(), FileLock can either wait until an exclusive lock is acquired (Blocking), or fail immediately (Non Blocking), but it can also try a configurable amount of time to acquire a Non Blocking exclusive lock, and wait a configurable amount of time between each attempts. FileLock can either lock a file (Self Locking) or create a file.lock and lock it instead (External Locking)

Installation

Math can be installed using composer :

FileLock is also included in OpinHelper which packages several bellow "Swiss Army Knife" level Helpers covering some of the most annoying aspects of php programing, such as UTF8 string manipulation, high precision Mathematics or properly locking a file

Should you need to work with php bellow 7.1, you can still use OpinHelper 0.x

Prerequisites

FileLock has no specific dependencies

External Locking

This locking strategy does not lock the input filePath itself but rather creates a new file $lockFilePath = "$inputFilePath.lock"; and attempts to flock() it instead This method is preferred in highly concurrent usages, where many processes will try to write the same file at once, such as file caching. Because this allows us to first try to open the .lock file in write mode and fail back to read mode before a flock() is eventually attempted

By using a separate file for locking, we make sure that every write waiting for the lock (this should be done in Blocking mode) does not hold any handle on the cache file itself while it is most likely already being intensively read

By failing back to read mode when write failed, we again lower the write handles to a single one, only when the external .lock file needs to be created. Altogether, this means that after warm up, each process waiting to write on the same file will be holding a read handle on the .lock file, while a single write one is at most used to actually write the cache file. As write handles are costly to open, approximately ten times slower than read handles, doing this can end up making some difference

External locking can also be useful when you do not want to actually flock() a file (could be already locked or used by some other program/process), or because you just need exclusivity for something as the lock file is then created for you and every PHP process will be able to check its existence

Please note that the external and empty .lock file is never deleted by FileLock and that its presence does not necessarily means that the lock is active

If the $lockFilePath = "$inputFilePath.lock"; version of the .lock file (that is where the $inputFilePath directory) is not writable, it is created in sys_get_temp_dir() instead, with a hashed basedir($inputFilePath) prefix in filename

Self Locking

This locking strategy does acquire a lock on the input filePath itself. It provide with more guarantees than the External Locking strategy as the file will be locked for any process, not just the ones checking the lock through FileLock and it is preferred when write sessions are not instant

It could make sense under specific circumstances to use a double lock, both External and Self, using two FileLock instances

In practice

In both External and Self locking, once you have an instance you can:

From there, you can get the underlying handle:

This is mostly useful when Self locking as you probably need the handle to actually write something.

Release lock

In all cases, locks are either released upon instance destruction or manually:

It is IMPORTANT to notice that when you acquire an Self lock, you need to keep the $lock instance alive until you are done with manipulating the file. Because FileLock is set to release its locks and handles when destroyed. This could happen if you where to acquire a lock in some function without storing the resulting instance outside of its scope.

Open Factory

FileLock comes with an handy factory to ease exclusively and self locked file opening:

Usage is pretty similar to fopen() except it returns a FileLock instance upon success (open + lock) instead of a resource and null when it failed.

Requirements

FileLock is tested against php 7.1, 7.2, 7.3, 7.4 and 8.0

Contributing

Contributions are welcome, do not hesitate to open issues and submit pull requests.

License

FileLock is open-sourced software licensed under the MIT license.


All versions of filelock with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1|^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package fab2s/filelock contains the following files

Loading the files please wait ....