PHP 8.3.31
Preview: DatabaseLock.php Size: 3.76 KB
/home/getspomw/royalsquad.us/vendor/laravel/framework/src/Illuminate/Cache/DatabaseLock.php

<?php

namespace Illuminate\Cache;

use Illuminate\Database\Connection;
use Illuminate\Database\QueryException;

class DatabaseLock extends Lock
{
    /**
     * The database connection instance.
     *
     * @var \Illuminate\Database\Connection
     */
    protected $connection;

    /**
     * The database table name.
     *
     * @var string
     */
    protected $table;

    /**
     * The prune probability odds.
     *
     * @var array
     */
    protected $lottery;

    /**
     * The default number of seconds that a lock should be held.
     *
     * @var int
     */
    protected $defaultTimeoutInSeconds;

    /**
     * Create a new lock instance.
     *
     * @param  \Illuminate\Database\Connection  $connection
     * @param  string  $table
     * @param  string  $name
     * @param  int  $seconds
     * @param  string|null  $owner
     * @param  array  $lottery
     * @return void
     */
    public function __construct(Connection $connection, $table, $name, $seconds, $owner = null, $lottery = [2, 100], $defaultTimeoutInSeconds = 86400)
    {
        parent::__construct($name, $seconds, $owner);

        $this->connection = $connection;
        $this->table = $table;
        $this->lottery = $lottery;
        $this->defaultTimeoutInSeconds = $defaultTimeoutInSeconds;
    }

    /**
     * Attempt to acquire the lock.
     *
     * @return bool
     */
    public function acquire()
    {
        try {
            $this->connection->table($this->table)->insert([
                'key' => $this->name,
                'owner' => $this->owner,
                'expiration' => $this->expiresAt(),
            ]);

            $acquired = true;
        } catch (QueryException) {
            $updated = $this->connection->table($this->table)
                ->where('key', $this->name)
                ->where(function ($query) {
                    return $query->where('owner', $this->owner)->orWhere('expiration', '<=', $this->currentTime());
                })->update([
                    'owner' => $this->owner,
                    'expiration' => $this->expiresAt(),
                ]);

            $acquired = $updated >= 1;
        }

        if (random_int(1, $this->lottery[1]) <= $this->lottery[0]) {
            $this->connection->table($this->table)->where('expiration', '<=', $this->currentTime())->delete();
        }

        return $acquired;
    }

    /**
     * Get the UNIX timestamp indicating when the lock should expire.
     *
     * @return int
     */
    protected function expiresAt()
    {
        $lockTimeout = $this->seconds > 0 ? $this->seconds : $this->defaultTimeoutInSeconds;

        return $this->currentTime() + $lockTimeout;
    }

    /**
     * Release the lock.
     *
     * @return bool
     */
    public function release()
    {
        if ($this->isOwnedByCurrentProcess()) {
            $this->connection->table($this->table)
                ->where('key', $this->name)
                ->where('owner', $this->owner)
                ->delete();

            return true;
        }

        return false;
    }

    /**
     * Releases this lock in disregard of ownership.
     *
     * @return void
     */
    public function forceRelease()
    {
        $this->connection->table($this->table)
            ->where('key', $this->name)
            ->delete();
    }

    /**
     * Returns the owner value written into the driver for this lock.
     *
     * @return string
     */
    protected function getCurrentOwner()
    {
        return optional($this->connection->table($this->table)->where('key', $this->name)->first())->owner;
    }

    /**
     * Get the name of the database connection being used to manage the lock.
     *
     * @return string
     */
    public function getConnectionName()
    {
        return $this->connection->getName();
    }
}

Directory Contents

Dirs: 3 × Files: 34

Name Size Perms Modified Actions
Console DIR
- drwxrwxrwx 2025-09-17 06:52:59
Edit Download
Events DIR
- drwxrwxrwx 2025-09-17 06:52:59
Edit Download
- drwxrwxrwx 2025-09-17 06:52:59
Edit Download
2.64 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
1.41 KB lrw-rw-rw- 2025-09-17 06:52:59
Edit Download
2.10 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
4.67 KB lrw-rw-rw- 2025-09-17 06:52:59
Edit Download
1.79 KB lrw-rw-rw- 2025-09-17 06:52:59
Edit Download
11.32 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
1.32 KB lrw-rw-rw- 2025-09-17 06:52:59
Edit Download
1.49 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
3.76 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
13.22 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
1.54 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
14.53 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
271 B lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
10.15 KB lrw-rw-rw- 2025-09-17 06:52:59
Edit Download
681 B lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
1.05 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
3.86 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
888 B lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
2.33 KB lrw-rw-rw- 2025-09-17 06:52:59
Edit Download
1.42 KB lrw-rw-rw- 2025-09-17 06:52:59
Edit Download
6.14 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
692 B lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
2.34 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
829 B lrw-rw-rw- 2025-09-17 06:52:59
Edit Download
7.61 KB lrw-rw-rw- 2025-09-17 06:52:59
Edit Download
1.73 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
12.87 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
3.03 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
3.44 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
20.17 KB lrw-rw-rw- 2025-09-17 06:52:59
Edit Download
1.25 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
421 B lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
2.50 KB lrw-rw-rw- 2025-09-17 06:52:58
Edit Download
2.46 KB lrw-rw-rw- 2025-09-17 06:52:59
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).