예제 #1
0
 public function testShouldCollectExistingGarbageCyclesOnFlushMethod()
 {
     $actualCount = 0;
     $expectedCount = 1;
     $this->overwrite('gc_collect_cycles', function () use(&$actualCount) {
         $actualCount++;
     });
     $control = new Control();
     $control->flush();
     $this->assertSame($expectedCount, $actualCount);
 }
예제 #2
0
<?php

declare (ticks=1);
require_once __DIR__ . '/../vendor/autoload.php';
use Arara\Process\Action\Callback;
use Arara\Process\Child;
use Arara\Process\Control;
$control = new Control();
$child = new Child(new Callback(function (Control $control) {
    echo 'This child process will sleep for 5 seconds' . PHP_EOL;
    $control->flush(5);
    echo 'This child just woke up' . PHP_EOL;
}), $control);
$child->start();
$control->flush(0.5);
if ($child->isRunning()) {
    echo 'Child is running' . PHP_EOL;
}
$child->terminate();
if (!$child->isRunning()) {
    echo 'Child was terminated' . PHP_EOL;
}
예제 #3
0
<?php

declare (ticks=1);
require_once __DIR__ . '/../vendor/autoload.php';
use Arara\Process\Action\Callback;
use Arara\Process\Child;
use Arara\Process\Control;
$control = new Control();
$child = new Child(new Callback(function (Control $control) {
    echo 'Child process is ' . $control->info()->getId() . PHP_EOL;
    $control->flush(1);
}), $control);
echo 'Parent process is ' . $control->info()->getId() . PHP_EOL;
$child->start();
if ($child->getStatus()->isSuccessful()) {
    echo 'Child successfully finished' . PHP_EOL;
}
 /**
  * Flash Control
  * @param number $seconds
  */
 public function flush($seconds = 0)
 {
     $this->control->flush($seconds);
 }
예제 #5
0
<?php

declare (ticks=1);
require_once __DIR__ . '/../vendor/autoload.php';
use Arara\Process\Control;
use Arara\Process\Pidfile;
$control = new Control();
$pidfile = new Pidfile($control, 'myapp', __DIR__);
try {
    $pidfile->initialize();
    echo 'Will sleep for 10 seconds, try to run it in another terminal' . PHP_EOL;
    $control->flush(10);
    $pidfile->finalize();
    // You may use register_shutdown_function([$pidfile, 'finalize']);
} catch (Exception $exception) {
    echo $exception->getMessage() . PHP_EOL;
    echo 'Running PID is #' . $pidfile->getProcessId() . PHP_EOL;
}
echo 'Finished' . PHP_EOL;
예제 #6
0
 /**
  * Default trigger for EVENT_FORK.
  *
  * Finishes the parent process.
  *
  * @param Control $control
  */
 public function handleFork(Control $control)
 {
     $control->flush(0.5);
 }