public function kill()
    {

        if (!$this->checkPid()) {
            // already dead
            $this->markAsDisappeared(sprintf('Did not kill job "%s" (id: %s), because it was already dead.', $this->getJobCode(), $this->getId()));
            return;
        }

        // let's be nice first (a.k.a. "Could you please stop running now?")
        if (posix_kill($this->getPid(), SIGINT)) {
            $this->log(sprintf('Sending SIGINT to job "%s" (id: %s)', $this->getJobCode(), $this->getId()));
        } else {
            $this->log(sprintf('Error while sending SIGINT to job "%s" (id: %s)', $this->getJobCode(), $this->getId()), Zend_Log::ERR);
        }

        // check if process terminates within 30 seconds
        $startTime = time();
        while (($waitTime = (time() - $startTime) < 30) && $this->checkPid()) {
            sleep(2);
        }

        if ($this->checkPid()) {
            // What, you're still alive? OK, time to say goodbye now. You had your chance...
            if (posix_kill($this->getPid(), SIGKILL)) {
                $this->log(sprintf('Sending SIGKILL to job "%s" (id: %s)', $this->getJobCode(), $this->getId()));
            } else {
                $this->log(sprintf('Error while sending SIGKILL to job "%s" (id: %s)', $this->getJobCode(), $this->getId()), Zend_Log::ERR);
            }
        } else {
            $this->log(sprintf('Killed job "%s" (id: %s) with SIGINT. Job terminated after %s second(s)', $this->getJobCode(), $this->getId(), $waitTime));
        }

        if ($this->checkPid()) {
            sleep(5);
            if ($this->checkPid()) {
                $this->log(sprintf('Killed job "%s" (id: %s) is still alive!', $this->getJobCode(), $this->getId()), Zend_Log::ERR);
                return; // without setting the status to "killed"
            }
        }

        $this
            ->setStatus(self::STATUS_KILLED)
            ->setFinishedAt(strftime('%Y-%m-%d %H:%M:%S', time()))
            ->save();
    }
public function kill()
    {

        if (!$this->checkPid()) {
            // already dead
            $this->markAsDisappeared(sprintf('Did not kill job "%s" (id: %s), because it was already dead.', $this->getJobCode(), $this->getId()));
            return;
        }

        // let's be nice first (a.k.a. "Could you please stop running now?")
        if (posix_kill($this->getPid(), SIGINT)) {
            $this->log(sprintf('Sending SIGINT to job "%s" (id: %s)', $this->getJobCode(), $this->getId()));
        } else {
            $this->log(sprintf('Error while sending SIGINT to job "%s" (id: %s)', $this->getJobCode(), $this->getId()), Zend_Log::ERR);
        }

        // check if process terminates within 30 seconds
        $startTime = time();
        while (($waitTime = (time() - $startTime) < 30) && $this->checkPid()) {
            sleep(2);
        }

        if ($this->checkPid()) {
            // What, you're still alive? OK, time to say goodbye now. You had your chance...
            if (posix_kill($this->getPid(), SIGKILL)) {
                $this->log(sprintf('Sending SIGKILL to job "%s" (id: %s)', $this->getJobCode(), $this->getId()));
            } else {
                $this->log(sprintf('Error while sending SIGKILL to job "%s" (id: %s)', $this->getJobCode(), $this->getId()), Zend_Log::ERR);
            }
        } else {
            $this->log(sprintf('Killed job "%s" (id: %s) with SIGINT. Job terminated after %s second(s)', $this->getJobCode(), $this->getId(), $waitTime));
        }

        if ($this->checkPid()) {
            sleep(5);
            if ($this->checkPid()) {
                $this->log(sprintf('Killed job "%s" (id: %s) is still alive!', $this->getJobCode(), $this->getId()), Zend_Log::ERR);
                return; // without setting the status to "killed"
            }
        }

        $this
            ->setStatus(self::STATUS_KILLED)
            ->setFinishedAt(strftime('%Y-%m-%d %H:%M:%S', time()))
            ->save();
    }
public function kill ( ) { if ( ! $ this -> checkPid ( ) ) { // already dead $ this -> markAsDisappeared ( sprintf ( 'Did not kill job "%s" (id: %s), because it was already dead.' , $ this -> getJobCode ( ) , $ this -> getId ( ) ) ) ; return ; } // let's be nice first (a.k.a. "Could you please stop running now?") if ( posix_kill ( $ this -> getPid ( ) , SIGINT ) ) { $ this -> log ( sprintf ( 'Sending SIGINT to job "%s" (id: %s)' , $ this -> getJobCode ( ) , $ this -> getId ( ) ) ) ; } else { $ this -> log ( sprintf ( 'Error while sending SIGINT to job "%s" (id: %s)' , $ this -> getJobCode ( ) , $ this -> getId ( ) ) , Zend_Log :: ERR ) ; } // check if process terminates within 30 seconds $ startTime = time ( ) ; while ( ( $ waitTime = ( time ( ) - $ startTime ) < 30 ) && $ this -> checkPid ( ) ) { sleep ( 2 ) ; } if ( $ this -> checkPid ( ) ) { // What, you're still alive? OK, time to say goodbye now. You had your chance... if ( posix_kill ( $ this -> getPid ( ) , SIGKILL ) ) { $ this -> log ( sprintf ( 'Sending SIGKILL to job "%s" (id: %s)' , $ this -> getJobCode ( ) , $ this -> getId ( ) ) ) ; } else { $ this -> log ( sprintf ( 'Error while sending SIGKILL to job "%s" (id: %s)' , $ this -> getJobCode ( ) , $ this -> getId ( ) ) , Zend_Log :: ERR ) ; } } else { $ this -> log ( sprintf ( 'Killed job "%s" (id: %s) with SIGINT. Job terminated after %s second(s)' , $ this -> getJobCode ( ) , $ this -> getId ( ) , $ waitTime ) ) ; } if ( $ this -> checkPid ( ) ) { sleep ( 5 ) ; if ( $ this -> checkPid ( ) ) { $ this -> log ( sprintf ( 'Killed job "%s" (id: %s) is still alive!' , $ this -> getJobCode ( ) , $ this -> getId ( ) ) , Zend_Log :: ERR ) ; return ; // without setting the status to "killed" } } $ this -> setStatus ( self :: STATUS_KILLED ) -> setFinishedAt ( strftime ( '%Y-%m-%d %H:%M:%S' , time ( ) ) ) -> save ( ) ; }
Kill this process

@return void
Kill this process