Browse Source

fix semaphores

main
ghost 1 year ago
parent
commit
43776b5ff4
  1. 18
      cli/yggo.php
  2. 13
      crontab/cleaner.php
  3. 12
      crontab/crawler.php

18
cli/yggo.php

@ -16,32 +16,32 @@ if (php_sapi_name() != 'cli') {
exit; exit;
} }
// Lock multi-thread execution // Stop CLI execution on cleaner process running
$semaphore = sem_get(crc32('crontab.crawler'), 1); $semaphore = sem_get(crc32('crontab.cleaner'), 1);
if (false === sem_acquire($semaphore, true)) { if (false === sem_acquire($semaphore, true)) {
CLI::danger(_('process locked by another thread.')); CLI::danger(_('stop crontab.cleaner is running in another thread.'));
CLI::break(); CLI::break();
exit; exit;
} }
// Stop CLI execution on cleaner process running // Stop CLI execution on crawler process running
$semaphore = sem_get(crc32('crontab.cleaner'), 1); $semaphore = sem_get(crc32('crontab.crawler'), 1);
if (false === sem_acquire($semaphore, true)) { if (false === sem_acquire($semaphore, true)) {
CLI::danger(_('stop crontab.cleaner is running in another thread.')); CLI::danger(_('stop crontab.crawler is running in another thread.'));
CLI::break(); CLI::break();
exit; exit;
} }
// Stop CLI execution on crawler process running // Lock multi-thread execution
$semaphore = sem_get(crc32('crontab.crawler'), 1); $semaphore = sem_get(crc32('cli.yggo'), 1);
if (false === sem_acquire($semaphore, true)) { if (false === sem_acquire($semaphore, true)) {
CLI::danger(_('stop crontab.crawler is running in another thread.')); CLI::danger(_('process locked by another thread.'));
CLI::break(); CLI::break();
exit; exit;
} }

13
crontab/cleaner.php

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

12
crontab/crawler.php

@ -1,20 +1,20 @@
<?php <?php
// Lock multi-thread execution // Stop crawler on cli running
$semaphore = sem_get(crc32('crontab.crawler'), 1); $semaphore = sem_get(crc32('cli.yggo'), 1);
if (false === sem_acquire($semaphore, true)) { if (false === sem_acquire($semaphore, true)) {
echo 'process locked by another thread.' . PHP_EOL; echo 'cli.yggo process running in another thread.' . PHP_EOL;
exit; exit;
} }
// Stop crawler on cli running // Lock multi-thread execution
$semaphore = sem_get(crc32('cli.yggo'), 1); $semaphore = sem_get(crc32('crontab.crawler'), 1);
if (false === sem_acquire($semaphore, true)) { if (false === sem_acquire($semaphore, true)) {
echo 'cli.yggo process running in another thread.' . PHP_EOL; echo 'process locked by another thread.' . PHP_EOL;
exit; exit;
} }

Loading…
Cancel
Save