/**
* Execute the daemon.
*
* @return void
*
* @since 1.7.0
*/
public function execute()
{
// Trigger the onBeforeExecute event
$this->triggerEvent('onBeforeExecute');
// Enable basic garbage collection.
gc_enable();
Log::add('Starting ' . $this->name, Log::INFO);
// Set off the process for becoming a daemon.
if ($this->daemonize()) {
// Declare ticks to start signal monitoring. When you declare ticks, PCNTL will monitor
// incoming signals after each tick and call the relevant signal handler automatically.
declare (ticks=1);
// Start the main execution loop.
while (true) {
// Perform basic garbage collection.
$this->gc();
// Don't completely overload the CPU.
usleep(1000);
// Execute the main application logic.
$this->doExecute();
}
} else {
Log::add('Starting ' . $this->name . ' failed', Log::INFO);
}
// Trigger the onAfterExecute event.
$this->triggerEvent('onAfterExecute');
}