File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,32 @@ method can be safely called repeatedly, even if the lock is already acquired.
68
68
across several requests. To disable the automatic release behavior, set the
69
69
third argument of the ``createLock() `` method to ``false ``.
70
70
71
+ Serializing Locks
72
+ ------------------
73
+
74
+ The ``Key `` contains the state of the ``Lock `` and can be serialized. This
75
+ allows the user to begin a long job in a process by acquiring the lock, and
76
+ continue the job in an other process using the same lock::
77
+
78
+ use Symfony\Component\Lock\Key;
79
+ use Symfony\Component\Lock\Lock;
80
+
81
+ $key = new Key('article.'.$article->getId());
82
+ $lock = new Lock($key, $this->store, 300, false);
83
+ $lock->acquire(true);
84
+
85
+ $this->bus->dispatch(new RefreshTaxonomy($article, $key));
86
+
87
+ .. note ::
88
+
89
+ Don't forget to disable the autoRelease to avoid releasing the lock when
90
+ the destructor is called.
91
+
92
+ Not all stores are compatible with serialization and cross-process locking:
93
+ for example, the kernel will automatically release semaphores acquired by the
94
+ :ref: `SemaphoreStore <lock-store-semaphore >` store. If you use an incompatible
95
+ store, an exception will be thrown when the application tries to serialize the key.
96
+
71
97
.. _lock-blocking-locks :
72
98
73
99
Blocking Locks
You can’t perform that action at this time.
0 commit comments