@@ -141,80 +141,6 @@ $airlock->withAdmitted('job:invoice', function () {
141141});
142142```
143143
144- ## PHP
145-
146- ``` php
147-
148- use Clegginabox\Airlock\Notifier\NullAirlockNotifier;
149- use Clegginabox\Airlock\Seal\LockSeal;
150- use Clegginabox\Airlock\Seal\SemaphoreSeal;
151- use Clegginabox\Airlock\QueueAirlock;
152- use Clegginabox\Airlock\Queue\RedisFifoQueue;
153- use Redis;
154- use Symfony\Component\Lock\LockFactory;
155- use Symfony\Component\Semaphore\SemaphoreFactory;
156-
157- $redis = new Redis();
158- $redis->connect('172.17.0.2');
159-
160- // Semaphore allows more than 1 user to enter at a time
161- $seal = new SemaphoreSeal(
162- factory: new SemaphoreFactory(
163- new \Symfony\Component\Semaphore\Store\RedisStore($redis)
164- ),
165- resource: 'my_airlock',
166- limit: 10,
167- weight: 1,
168- ttlInSeconds: 900,
169- autoRelease: false
170- );
171-
172- $seal = new LockSeal(
173- factory: new LockFactory(
174- new \Symfony\Component\Lock\Store\RedisStore($redis)
175- ),
176- resource: 'my_airlock',
177- ttlInSeconds: 900,
178- autoRelease: false
179- );
180-
181- // RedisFifoQueue (fair) or RedisLotteryQueue (random)
182- $queue = new RedisFifoQueue($redis);
183-
184- // NullAirlockNotifier or MercureAirlockNotifier
185- $notifier = new NullAirlockNotifier();
186-
187- // QueueAirlock or a free for all with OpportunisticAirlock
188- $airlock = new QueueAirlock(
189- seal: $seal,
190- queue: $queue,
191- notifier: $notifier,
192- topicPrefix: '/my_airlock'
193- );
194-
195- // Try and enter the airlock
196- $result = $airlock->enter($userId);
197-
198- if ($result->isAdmitted()) {
199- // Get the seal token
200- $token = $result->getToken();
201-
202- // ... Do your protected work ...
203-
204- // Heartbeat: Extend lease by another 5 minutes
205- $airlock->refresh($token, 300);
206-
207- // Done? Let the next person in!
208- $airlock->release($token);
209- } else {
210- // Access Denied! Join the line
211- $queuePosition = $airlock->getPosition($userId);
212-
213- // Bored of waiting?
214- $airlock->leave($userId);
215- }
216- ```
217-
218144## Symfony bundle
219145
220146Register the bundle (if not using Flex):
0 commit comments