Skip to content

Make lock key prefix configurable (currently hardcoded php-malkusch-lock) #85

@mkduew

Description

@mkduew

Currently, the lock key prefix is hardcoded in LockUtil:

final public function getKeyPrefix(): string
{
    return 'php-malkusch-lock';
}

This makes it impossible to configure or shorten the prefix from the outside.

Problem

This is especially problematic when using MySQLMutex, because:
• MySQL limits GET_LOCK() names to 64 characters
• The default prefix php-malkusch-lock already consumes 17 characters
• This significantly reduces the usable length for application-specific lock keys
• In practice, this can easily lead to unexpected failures when keys are generated dynamically

Why configurability matters

Being able to configure the prefix would allow:
• Shorter prefixes when strict limits apply (e.g. MySQL)
• Custom prefixes to avoid collisions between applications
• More flexibility for users who already manage namespacing on their own

Suggested solution

One of the following (or similar) approaches would be very helpful:
• Allow passing a custom key prefix via constructor / configuration
• Provide a setter or optional parameter for LockUtil
• Or make the prefix overridable instead of hardcoded

This would be particularly useful in combination with MySQLMutex, where every character counts.

Thanks a lot for your work on this library, and happy to provide more context or examples if needed!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions