: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
class Utility_DatabaseLock implements Utility_Lock {
const DEFAULT_TIMEOUT = 30;
private $expirationTimestamp;
public function __construct($dbController, $key, $timeout = null) {
$this->wpdb = $dbController->get_wpdb();
$this->table = $dbController->settings;
$this->key = "lock:{$key}";
$this->timeout = self::resolveTimeout($timeout);
private static function resolveTimeout($timeout) {
$timeout = ini_get('max_execution_time');
$timeout = (int) $timeout;
if ($timeout <= 0 || $timeout > self::MAX_TIMEOUT)
return self::DEFAULT_TIMEOUT;
private function clearExpired($timestamp) {
$this->wpdb->query($this->wpdb->prepare(<<<SQL
, $this->key, $timestamp));
private function insert($expirationTimestamp) {
$result = $this->wpdb->query($this->wpdb->prepare(<<<SQL
, $this->key, $expirationTimestamp));
public function acquire($delay = self::DEFAULT_DELAY) {
$attempts = (int) ($this->timeout * 1000000 / $delay);
for (; $attempts > 0; $attempts--) {
$this->clearExpired($timestamp);
$expirationTimestamp = $timestamp + $this->timeout;
$locked = $this->insert($expirationTimestamp);
$this->expirationTimestamp = $expirationTimestamp;
throw new RuntimeException("Failed to acquire lock {$this->key}");
private function delete($expirationTimestamp) {
'value' => $expirationTimestamp
public function release() {
if ($this->expirationTimestamp === null)
$this->delete($this->expirationTimestamp);
$this->expirationTimestamp = null;