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') { @@ -16,32 +16,32 @@ if (php_sapi_name() != 'cli') {
exit;
}
// Lock multi-thread execution
$semaphore = sem_get(crc32('crontab.crawler'), 1);
// Stop CLI execution on cleaner process running
$semaphore = sem_get(crc32('crontab.cleaner'), 1);
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();
exit;
}
// Stop CLI execution on cleaner process running
$semaphore = sem_get(crc32('crontab.cleaner'), 1);
// Stop CLI execution on crawler process running
$semaphore = sem_get(crc32('crontab.crawler'), 1);
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();
exit;
}
// Stop CLI execution on crawler process running
$semaphore = sem_get(crc32('crontab.crawler'), 1);
// Lock multi-thread execution
$semaphore = sem_get(crc32('cli.yggo'), 1);
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();
exit;
}

13
crontab/cleaner.php

@ -1,23 +1,24 @@ @@ -1,23 +1,24 @@
<?php
// Lock multi-thread execution
$semaphore = sem_get(crc32('crontab.cleaner'), 1);
// Stop cleaner on cli running
$semaphore = sem_get(crc32('cli.yggo'), 1);
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;
}
// Stop cleaner on cli running
$semaphore = sem_get(crc32('cli.yggo'), 1);
// Lock multi-thread execution
$semaphore = sem_get(crc32('crontab.cleaner'), 1);
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;
}
// Load system dependencies
require_once(__DIR__ . '/../config/app.php');
require_once(__DIR__ . '/../library/curl.php');

12
crontab/crawler.php

@ -1,20 +1,20 @@ @@ -1,20 +1,20 @@
<?php
// Lock multi-thread execution
$semaphore = sem_get(crc32('crontab.crawler'), 1);
// Stop crawler on cli running
$semaphore = sem_get(crc32('cli.yggo'), 1);
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;
}
// Stop crawler on cli running
$semaphore = sem_get(crc32('cli.yggo'), 1);
// Lock multi-thread execution
$semaphore = sem_get(crc32('crontab.crawler'), 1);
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;
}

Loading…
Cancel
Save