Page MenuHomePhorge

abstract class PhutilDaemon
Phorge Technical Documentation (Daemons)

Scaffolding for implementing robust background processing scripts.

Autoscaling

Autoscaling automatically launches copies of a daemon when it is busy (scaling the pool up) and stops them when they're idle (scaling the pool down). This is appropriate for daemons which perform highly parallelizable work.

To make a daemon support autoscaling, the implementation should look something like this:

while (!$this->shouldExit()) {
  if (work_available()) {
    $this->willBeginWork();
    do_work();
    $this->sleep(0);
  } else {
    $this->willBeginIdle();
    $this->sleep(1);
  }
}

In particular, call willBeginWork() before becoming busy, and willBeginIdle() when no work is available. If the daemon is launched into an autoscale pool, this will cause the pool to automatically scale up when busy and down when idle.

Launching a daemon which does not make these callbacks into an autoscale pool will have no effect.

Tasks

Communicating With the Overseer

No methods for this task.

Autoscaling Daemon Pools

  • protected function willBeginWork() — Prepare to become busy. This may autoscale the pool up.
  • protected function willBeginIdle() — Prepare to idle. This may autoscale the pool down.

Other Methods

Methods

public function __get($name)
Inherited

This method is not documented.
Parameters
$name
Return
wild

public function __set($name, $value)
Inherited

This method is not documented.
Parameters
$name
$value
Return
wild

public function current()
Inherited

This method is not documented.
Return
wild

public function key()
Inherited

This method is not documented.
Return
wild

public function next()
Inherited

This method is not documented.
Return
wild

public function rewind()
Inherited

This method is not documented.
Return
wild

public function valid()
Inherited

This method is not documented.
Return
wild

private function throwOnAttemptedIteration()
Inherited

This method is not documented.
Return
wild

public function getPhobjectClassConstant($key, $byte_limit)
Inherited

Phobject

Read the value of a class constant.

This is the same as just typing self::CONSTANTNAME, but throws a more useful message if the constant is not defined and allows the constant to be limited to a maximum length.

Parameters
string$keyName of the constant.
int|null$byte_limitMaximum number of bytes permitted in the value.
Return
stringValue of the constant.

final public function setVerbose($verbose)

This method is not documented.
Parameters
$verbose
Return
wild

final public function getVerbose()

This method is not documented.
Return
wild

final public function setScaledownDuration($scaledown_duration)

This method is not documented.
Parameters
$scaledown_duration
Return
wild

final public function getScaledownDuration()

This method is not documented.
Return
wild

final public function __construct($argv)

This method is not documented.
Parameters
array$argv
Return
this//Implicit.//

final public function __destruct()

This method is not documented.
Return
wild

final public function stillWorking()

This method is not documented.
Return
wild

final public function shouldExit()

This method is not documented.
Return
wild

final protected function shouldHibernate($duration)

This method is not documented.
Parameters
$duration
Return
wild

final protected function sleep($duration)

This method is not documented.
Parameters
$duration
Return
wild

protected function willSleep($duration)

This method is not documented.
Parameters
$duration
Return
wild

public static function onTermSignal($signo)

This method is not documented.
Parameters
$signo
Return
wild

final protected function getArgv()

This method is not documented.
Return
wild

final public function execute()

This method is not documented.
Return
wild

abstract protected function run()

This method is not documented.
Return
wild

final public function setTraceMemory()

This method is not documented.
Return
wild

final public function getTraceMemory()

This method is not documented.
Return
wild

final public function setTraceMode()

This method is not documented.
Return
wild

final public function getTraceMode()

This method is not documented.
Return
wild

final public function onGracefulSignal($signo)

This method is not documented.
Parameters
$signo
Return
wild

final public function onNotifySignal($signo)

This method is not documented.
Parameters
$signo
Return
wild

protected function onNotify($signo)

This method is not documented.
Parameters
$signo
Return
wild

protected function willRun()

This method is not documented.
Return
wild

protected function didSetTraceMode()

This method is not documented.
Return
wild

final protected function log($message)

This method is not documented.
Parameters
$message
Return
wild

private static function didCatchSignal($signo)

This method is not documented.
Parameters
$signo
Return
wild

private function beginStdoutCapture()

This method is not documented.
Return
wild

private function endStdoutCapture()

This method is not documented.
Return
wild

public function didReceiveStdout($data)

This method is not documented.
Parameters
$data
Return
wild

private function encodeOverseerMessage($type, $data)

This method is not documented.
Parameters
$type
$data
Return
wild

private function emitOverseerMessage($type, $data)

This method is not documented.
Parameters
$type
$data
Return
wild

public static function errorListener($event, $value, $metadata)

This method is not documented.
Parameters
$event
$value
array$metadata
Return
wild

protected function willBeginWork()

Prepare to become busy. This may autoscale the pool up.

This notifies the overseer that the daemon has become busy. If daemons that are part of an autoscale pool are continuously busy for a prolonged period of time, the overseer may scale up the pool.

Return
this

protected function willBeginIdle()

Prepare to idle. This may autoscale the pool down.

This notifies the overseer that the daemon is no longer busy. If daemons that are part of an autoscale pool are idle for a prolonged period of time, they may exit to scale the pool down.

Return
this

protected function getIdleDuration()

This method is not documented.
Return
wild