1. Go to this page and download the library: Download asinfotrack/yii2-semaphore 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/ */
class SemaphoreDemoController extends \yii\console\Controller
{
public function actionWaitForLock()
{
Yii::$app->semaphore->acquire('my-lock', true);
//do the actual work
Yii::$app->semaphore->release('my-lock');
}
public function actionSkipIfNotAvailable()
{
if (!Yii::$app->semaphore->acquire('my-lock', false)) {
$this->stderr('Lock already taken');
return ExitCode::UNAVAILABLE;
}
//do the actual work
Yii::$app->semaphore->release('my-lock');
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.