1. Go to this page and download the library: Download freerkminnema/synchronized library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$nameOnTicket = Request::get('name-on-ticket');
$ticket = synchronized(function () use ($nameOnTicket) {
// This is bad, because everytime $nameOnTicket has a
// different value, the Atomic Lock Key will be different.
return [
'name' => $nameOnTicket,
'number' => Cache::increment('ticket-number'),
];
});
$nameOnTicket = Request::get('name-on-ticket');
$ticket = synchronized(function () use ($nameOnTicket) {
// Now it doesn't matter what the value of
// $nameOnTicket is, since the Atomic Lock Key is fixed.
return [
'name' => $nameOnTicket,
'number' => Cache::increment('ticket-number'),
];
}, 'atomic-ticket-number-increment');