diff --git a/cli/yggo.php b/cli/yggo.php index 44d3286..457a983 100644 --- a/cli/yggo.php +++ b/cli/yggo.php @@ -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); diff --git a/crontab/cleaner.php b/crontab/cleaner.php index ac35629..87a74f0 100644 --- a/crontab/cleaner.php +++ b/crontab/cleaner.php @@ -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'); diff --git a/crontab/crawler.php b/crontab/crawler.php index 70468e3..798b905 100644 --- a/crontab/crawler.php +++ b/crontab/crawler.php @@ -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');