fix semaphores

This commit is contained in:
ghost 2023-08-01 17:53:14 +03:00
parent 48e0482dbd
commit 43776b5ff4
3 changed files with 28 additions and 27 deletions

View File

@ -16,16 +16,6 @@ if (php_sapi_name() != 'cli') {
exit;
}
// Lock multi-thread execution
$semaphore = sem_get(crc32('crontab.crawler'), 1);
if (false === sem_acquire($semaphore, true)) {
CLI::danger(_('process locked by another thread.'));
CLI::break();
exit;
}
// Stop CLI execution on cleaner process running
$semaphore = sem_get(crc32('crontab.cleaner'), 1);
@ -46,6 +36,16 @@ if (false === sem_acquire($semaphore, true)) {
exit;
}
// Lock multi-thread execution
$semaphore = sem_get(crc32('cli.yggo'), 1);
if (false === sem_acquire($semaphore, true)) {
CLI::danger(_('process locked by another thread.'));
CLI::break();
exit;
}
// Connect database
$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD);

View File

@ -1,5 +1,14 @@
<?php
// Stop cleaner on cli running
$semaphore = sem_get(crc32('cli.yggo'), 1);
if (false === sem_acquire($semaphore, true)) {
echo 'cli.yggo process running in another thread.' . PHP_EOL;
exit;
}
// Lock multi-thread execution
$semaphore = sem_get(crc32('crontab.cleaner'), 1);
@ -9,14 +18,6 @@ if (false === sem_acquire($semaphore, true)) {
exit;
}
// Stop cleaner on cli running
$semaphore = sem_get(crc32('cli.yggo'), 1);
if (false === sem_acquire($semaphore, true)) {
echo 'cli.yggo process running in another thread.' . PHP_EOL;
exit;
}
// Load system dependencies
require_once(__DIR__ . '/../config/app.php');

View File

@ -1,14 +1,5 @@
<?php
// Lock multi-thread execution
$semaphore = sem_get(crc32('crontab.crawler'), 1);
if (false === sem_acquire($semaphore, true)) {
echo 'process locked by another thread.' . PHP_EOL;
exit;
}
// Stop crawler on cli running
$semaphore = sem_get(crc32('cli.yggo'), 1);
@ -18,6 +9,15 @@ if (false === sem_acquire($semaphore, true)) {
exit;
}
// Lock multi-thread execution
$semaphore = sem_get(crc32('crontab.crawler'), 1);
if (false === sem_acquire($semaphore, true)) {
echo 'process locked by another thread.' . PHP_EOL;
exit;
}
// Load system dependencies
require_once(__DIR__ . '/../config/app.php');
require_once(__DIR__ . '/../library/ftp.php');