Download the PHP package icy8/php-lock-system without Composer

On this page you can find all versions of the php package icy8/php-lock-system. 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 php-lock-system

php-lock-system

介绍

基于php的锁机制

软件架构

  1. php>=7.0
  2. 基于redis/file锁
  3. 默认使用的是redis锁

使用说明

  1. 推荐使用redis锁
  2. 不推荐复用实例
  3. 构造函数传入一个可以阻塞进程的唯一key,视业务而定
  4. 文件锁的key是对应的文件名
  5. 文件锁运行过程中默认会产生一个名为icy8/php_lock_system/的文件夹
  6. 如果闭包内有结果返回,那么在run方法可以获取到这个结果。
  7. 安装:composer require icy8/php-lock-system

已知问题

原理解析

  1. 当锁存在时另外的进程就需要等待这个锁释放后才能执行相关的事件闭包。即使用while(true)等待锁。
  2. 默认策略是等待释放锁超时后马上执行事件闭包,即忽略锁,这样操作的后果就是数据依然会有并发问题。
  3. 最新一个版本的加入了一个释放锁超时后抛出异常,退出当前程序。这样操作的后果就是这一次请求的数据会丢失

样例

目前只支持闭包运行,请勿传非\Closure类型的参数

  1. 使用默认参数运行

  2. redis锁

  3. redis连接配置

  4. 文件锁

支持的运行方式

  1. 通过静态方法调起运行

  2. 对象

  3. 函数名

  4. 其他案例

  5. 锁超时后抛出异常

错误用法

  1. 数据库事务

    错误例子:

    错误改正:

  2. die、exit等终止脚本的函数

    因为释放锁是在闭包运行完成后进行的,所以通过这类函数直接退出程序会导致锁无法正确释放掉。 这样会出现不必要的锁释放等待,影响程序效率。

    错误例子:

    错误改正:

    如果业务中必须要用到这类函数,那么建议你在终止脚本前手动释放锁:


All versions of php-lock-system with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 icy8/php-lock-system contains the following files

Loading the files please wait ....