Example #1
0
 public function testShouldWriteProcessIdOnPidfileWhenInitializing()
 {
     $processId = 123456;
     $actualContent = null;
     $expectedContent = $processId . PHP_EOL;
     $this->restore('fwrite')->overwrite('fwrite', function () use(&$actualContent) {
         $actualContent = func_get_arg(1);
         return true;
     });
     $signal = $this->getMock('Arara\\Process\\Control\\Signal');
     $signal->expects($this->any())->method('send')->will($this->returnValue(false));
     $info = $this->getMock('Arara\\Process\\Control\\Info');
     $info->expects($this->any())->method('getId')->will($this->returnValue($processId));
     $control = $this->getMock('Arara\\Process\\Control');
     $control->expects($this->any())->method('signal')->will($this->returnValue($signal));
     $control->expects($this->any())->method('info')->will($this->returnValue($info));
     $pidfile = new Pidfile($control);
     $pidfile->initialize();
     $this->assertSame($expectedContent, $actualContent);
 }
Example #2
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;