Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Fslock Laravel Package

yriveiro/php-fslock

A lightweight PHP library for managing file locks. It wraps flock() to acquire shared or exclusive locks, supports blocking and non-blocking modes, and provides simple lock release, helping coordinate concurrent processes and prevent race conditions.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Build vs. buy (adopt vs. write 15 lines). This package wraps PHP's native flock() into a small lock object with acquire/release semantics. The real product decision it informs is whether a wrapper earns a dependency slot at all. PHP's flock() is one function call; a package must justify itself with ergonomics (named locks, blocking vs. non-blocking, timeouts, cleanup, destructor-based release). Evaluate the source against that bar, not its star count. The 3.0.0 release trims the API (removal of destroy()) and adds lock-path configuration — it is converging on a smaller, sharper surface, which strengthens the "buy/borrow rather than build" case slightly, but does not change the underlying math.
  • Single-host concurrency strategy. flock is an OS-level advisory lock scoped to a machine and filesystem. It directly supports decisions like "do we need Redis/DynamoDB locking, or is one host enough for now?" Choosing this package is an explicit bet that the workload runs on one machine — which is a legitimate near-term call for cron jobs, report generators, and nightly imports.
  • Cron/CLI overlap prevention. The clearest use case: nightly jobs, data syncs, invoice generation, and artisan-style commands that must not double-run when a previous invocation is slow. This is a product-correctness issue (duplicate charges, duplicate emails), not a nice-to-have.
  • Queue/worker deduplication on a single node. For Laravel deployments where cache is file-based or local to one host, this can back a "one at a time" guard without standing up shared infrastructure. If the app already uses a shared cache or database, prefer the framework's built-in withoutOverlapping() middleware — fewer moving parts.
  • Where lock files live is now a configurable product decision. 3.0.0 adds a constructor parameter for the lock storage path. That is genuinely useful: you can namespace locks per application, keep them out of a world-writable /tmp, or place them alongside app storage for easier cleanup and inspection. It also creates a new failure mode to decide on deliberately — do not point this at a network mount (NFS/EFS/SMB) under the assumption that it makes the lock cross-host. flock on network filesystems is unreliable; the parameter relocates the file, it does not distribute the lock.
  • Runtime/platform upgrade dependency. The 3.0.0 bump to a PHP 7.x minimum is a real constraint, not a footnote. If any part of the estate still runs PHP 5.x — legacy hosts, an old container image, a shared cron box — adoption of this version is blocked, and the "cheap guardrail" framing collapses until the runtime is upgraded. This is a question for the platform owner, not the feature team.
  • Roadmap signal for horizontal scaling. Adopting this locks in an assumption. That makes it a useful forcing question for the roadmap: when we add a second app server or move to containers/Kubernetes, what replaces this? If the answer is "nothing, we forgot," you have a production incident queued up.
  • Maintenance-risk acceptance — revised. The earlier read was "unmaintained since 2018." 3.0.0 disproves that: someone is still cutting releases. But the cadence is evidently very slow and the project remains tiny (low stars, no visible release cadence commitment). The correct posture shifts from "assume abandoned" to "maintained sporadically, treat as vendored code." That is a mild improvement in vendor risk and a reminder that a major version can land at any time — pin the version.

When to Consider This Package

Consider it when all of the following hold:

  • The workload is single-host. One VM, one container, one bare-metal box — no autoscaling, no replicas.
  • The lock file lives on a local filesystem — including when you use the new 3.0.0 path parameter. flock semantics are unreliable on NFS and other network mounts; assume local disk only. Configure the path for isolation and hygiene, not for sharing.
  • The runtime is PHP 7.x or newer across every host that will use it. 3.0.0 is a hard floor.
  • The lock protects against rare, coarse-grained collisions (job overlap), not high-frequency contention. Per-request locking on a busy endpoint will serialize traffic and hurt latency.
  • You're comfortable reading the (small) source and vendoring/forking it if needed. Low stars means you are effectively the maintainer, and the 3.0.0 breaking changes are exactly the kind of thing you may need to patch yourself later.
  • The failure mode of a missed lock is recoverable (a skipped run, a retry) rather than catastrophic.

Look elsewhere — or skip the dependency entirely — when:

  • You run more than one host, pod, or container. flock gives no cross-machine mutual exclusion. You will get false confidence: the lock "works" in staging and silently fails to protect anything in production. Use Redis (SET NX PX), a database advisory lock, or Laravel's cache-based locks with a shared store.
  • The cache/session backend is already shared. If Redis or a central DB is in the stack, the framework's withoutOverlapping() or a Redis lock is better supported and already observable.
  • You need observability. This package still emits no metrics, events, or structured logging. If you need to alert on lock contention or stuck locks, plan to wrap it yourself.
  • Locks must survive process death gracefully with TTLs. flock releases on process exit, which is good, but there is no lease/expiry concept. Long-running hung processes holding a lock are a real operational risk.
  • You need a stable API contract. 3.0.0 removed destroy() outright with no deprecation path and no shim. Any code holding a lock object and calling destroy() will fatal after upgrade. This is a small library being versioned like a library with real users; budget a grep-and-fix pass every time.
  • Regulated or security-reviewed environments. A low-activity package still draws audit questions; a five-line in-house wrapper around flock() is often the easier approval path, and now also the easier-to-upgrade path given the PHP 7 floor.
  • Short scripts. If the lock is needed in exactly one place, write it inline. Adopt a package when there are several call sites with consistent semantics.

If already adopted: treat 3.0.0 as a migration, not a patch. Find every destroy() call site, drop it, and confirm lock release is still covered by the destructor/release path. Then set the new lock path explicitly rather than inheriting a default — a deliberate, documented directory is easier to operate and to back up or clean than an implicit one.

How to Pitch It (Stakeholders)

To executives: We have a class of operational bugs — the same nightly job running twice, duplicated customer emails, double-generated invoices — caused by processes overlapping. This is a small, MIT-licensed utility that prevents that on a single server for essentially zero cost and no infrastructure change. It is not a platform investment and it is not a long-term commitment; it is a cheap guardrail that buys us correctness now. Two things to flag. First, it only protects a single machine, so the moment we scale to multiple app servers or containers, we must replace it with a distributed lock — a known, bounded piece of work worth putting on the roadmap before an incident finds it for us. Second, it now requires PHP 7 across the hosts that use it, and its new major version changed its API, so there is a small migration cost if we already depend on it. The project also shipped its first release in years, which is mildly reassuring on maintenance but confirms that version bumps can arrive whenever the maintainer chooses — so we pin it.

To engineering: It's a thin, readable wrapper over flock(). Low risk, low surface area, no transitive dependency weight. Changes in 3.0.0 to account for: PHP 7.x minimum; explicit return types (no behavioral change); a new constructor parameter for the lock storage directory; and destroy() removed with no deprecation shim — grep for it before upgrading, and rely on release/destructor for cleanup instead of reusing a destroyed instance. Three caveats to accept explicitly: (1) it is maintained only sporadically, so treat it as vendored code — read it, pin it, and be prepared to fork or replace it; (2) flock is host-local and unreliable on network filesystems, so this is a single-node solution only — the new path parameter does not make it cross-host, and pointing it at a shared mount is a trap, not a feature; (3) there is no observability or TTL/lease concept, so hung processes can hold a lock indefinitely. Prefer the framework's built-in withoutOverlapping() if a shared cache or database already exists; use this only where a shared store doesn't. Wrap it in a small service so the eventual swap to Redis or a DB lock is a one-file change, set the lock directory explicitly in config, and add a log line on lock acquisition failure so we can see contention in production.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment