sfinktah / php-remote-lock
There is no license information available for the latest version (dev-master) of this package.
Private simple network aware mutex lock for PHP
dev-master
2023-12-02 09:56 UTC
Requires
- php: ^7.1|^8.0
- ext-ctype: *
- ext-curl: *
- ext-hash: *
- ext-json: *
- ext-mbstring: *
- ext-pcntl: *
This package is auto-updated.
Last update: 2025-01-31 00:56:38 UTC
README
With composer
composer require php-remote-lock
Without composer
git clone https://github.com/sfinktah/php-remote-lock /path/to/project-root/RemoteLock
/path/to/project-root/index.php
<?php require_once "RemoteLock/RemoteLock.php";
Obtaining a lock
function main(...$args) { $lock = new \Sfinktah\RemoteLock\SingleInstanceRemoteLock('lock_name', 'https://markt14.streetfx.au'); if ($lock->lockCall(3600 /* 1 hour */, function(...$args) { doWork(...$args); }, ...$args)) { printf("Work Done\n"); } else { printf("Failed to acquire lock\n"); } }
Installing the locking server
/etc/systemd/system/php-remote-lock.service
[Unit] Description=PHP Remote Lock Master Service After=network.target [Service] ExecStart=/usr/bin/python3 /path/to/RemoteLock/libexec/idarest_master.py Restart=always [Install] WantedBy=default.target
sudo systemctl enable php-remote-lock.service
sudo systemctl start php-remote-lock.service
sudo systemctl show php-remote-lock.service
/etc/nginx/nginx.conf
server { # ... location /lock { proxy_pass http://127.0.0.1:28612; } # ... }
sudo nginx -t &&
sudo systemctl restart nginx