+ $this->synchronized(function () use ($data) {
+ file_put_contents(
+ $this->datastore,
+ $data
+ );
+ });
+ }
+
+ /**
+ * Wrapper applying mutex to provided function.
+ * If the lock can't be acquired (e.g. some shared hosting provider), we execute the function without mutex.
+ *
+ * @see https://github.com/shaarli/Shaarli/issues/1650
+ *
+ * @param callable $function
+ */
+ protected function synchronized(callable $function): void
+ {
+ try {
+ $this->mutex->synchronized($function);
+ } catch (LockAcquireException $exception) {
+ $function();
+ }