Final Class Yiisoft\Queue\Cli\SignalLoop
| Inheritance | Yiisoft\Queue\Cli\SignalLoop |
|---|---|
| Implements | Yiisoft\Queue\Cli\LoopInterface |
| Uses Traits | Yiisoft\Queue\Cli\SoftLimitTrait |
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $exit | boolean | Yiisoft\Queue\Cli\SignalLoop | |
| $memorySoftLimit | integer | Yiisoft\Queue\Cli\SignalLoop | |
| $pause | boolean | Yiisoft\Queue\Cli\SignalLoop |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Queue\Cli\SignalLoop | |
| canContinue() | Checks signals state. | Yiisoft\Queue\Cli\SignalLoop |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| dispatchSignals() | Yiisoft\Queue\Cli\SignalLoop | |
| getMemoryLimit() | Yiisoft\Queue\Cli\SignalLoop | |
| memoryLimitReached() | Yiisoft\Queue\Cli\SoftLimitTrait |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| SIGNALS_EXIT | [ SIGHUP, SIGINT, SIGTERM, ] | Yiisoft\Queue\Cli\SignalLoop | |
| SIGNALS_RESUME | [ SIGCONT, ] | Yiisoft\Queue\Cli\SignalLoop | |
| SIGNALS_SUSPEND | [ SIGTSTP, ] | Yiisoft\Queue\Cli\SignalLoop |
Property Details
Method Details
| public mixed __construct ( integer $memorySoftLimit = 0 ) | ||
| $memorySoftLimit | integer |
Soft RAM limit in bytes. The loop won't let you continue to execute the program if soft limit is reached. Zero means no limit. |
public function __construct(protected int $memorySoftLimit = 0)
{
foreach (self::SIGNALS_EXIT as $signal) {
pcntl_signal($signal, fn () => $this->exit = true);
}
foreach (self::SIGNALS_SUSPEND as $signal) {
pcntl_signal($signal, fn () => $this->pause = true);
}
foreach (self::SIGNALS_RESUME as $signal) {
pcntl_signal($signal, fn () => $this->pause = false);
}
}
Checks signals state.
{@inheritdoc}
| public boolean canContinue ( ) |
public function canContinue(): bool
{
if ($this->memoryLimitReached()) {
return false;
}
return $this->dispatchSignals();
}
| protected boolean dispatchSignals ( ) |
protected function dispatchSignals(): bool
{
pcntl_signal_dispatch();
// Wait for resume signal until the loop is suspended
while ($this->pause && !$this->exit) {
usleep(10000);
pcntl_signal_dispatch();
}
return !$this->exit;
}
| protected integer getMemoryLimit ( ) |
protected function getMemoryLimit(): int
{
return $this->memorySoftLimit;
}
| protected boolean memoryLimitReached ( ) |
protected function memoryLimitReached(): bool
{
$limit = $this->getMemoryLimit();
if ($limit !== 0) {
$usage = memory_get_usage(true);
if ($usage >= $limit) {
return true;
}
}
return false;
}
Signup or Login in order to comment.