Ko\ProcessManager::onShutdown PHP Method

onShutdown() public method

Master process shutdown handler. Shutdown handler called right after the SIGTERM catches by this class.
public onShutdown ( callable $callable )
$callable callable
    public function onShutdown(callable $callable)
    {
        $this->internalOn('shutdown', $callable);
        return $this;
    }

Usage Example

コード例 #1
0
 public function testShutdownHandlerWasCalledOnSigTerm()
 {
     $process = $this->manager->fork(function (Process $p) {
         $sm = $p->getSharedMemory();
         $m = new ProcessManager();
         $m->onShutdown(function () use(&$sm) {
             $sm['wasCalled'] = true;
         })->fork(function () {
             usleep(300000);
         });
         $sm['ready'] = true;
         $m->wait();
     });
     $this->waitReady($process);
     $process->kill();
     $this->manager->wait();
     $sm = $process->getSharedMemory();
     $this->assertTrue($sm['wasCalled']);
 }