/** * Error handler * @param integer $errno * @param string $errstr * @param string $errfile * @param integer $errline * @param array $errcontext */ public static function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) { Daemon::$noError = false; $l = error_reporting(); if ($l === 0) { if (!Daemon::$restrictErrorControl) { return; } } elseif (!($l & $errno)) { return; } static $errtypes = [E_ERROR => 'Fatal error', E_WARNING => 'Warning', E_PARSE => 'Parse error', E_NOTICE => 'Notice', E_PARSE => 'Parse error', E_USER_ERROR => 'Fatal error (userland)', E_USER_WARNING => 'Warning (userland)', E_USER_NOTICE => 'Notice (userland)', E_STRICT => 'Notice (userland)', E_RECOVERABLE_ERROR => 'Fatal error (recoverable)', E_DEPRECATED => 'Deprecated', E_USER_DEPRECATED => 'Deprecated (userland)']; $errtype = $errtypes[$errno]; Daemon::log($errtype . ': ' . $errstr . ' in ' . $errfile . ':' . $errline . "\n" . Debug::backtrace()); if (Daemon::$context instanceof \PHPDaemon\Request\Generic) { Daemon::$context->out('<strong>' . $errtype . '</strong>: ' . $errstr . ' in ' . basename($errfile) . ':' . $errline . '<br />'); } }
/** * Send data to the connection. Note that it just writes to buffer that flushes at every baseloop * @param string $data Data to send * @return boolean Success */ public function write($data) { if (!$this->alive) { Daemon::log('Attempt to write to dead IOStream (' . get_class($this) . ')'); return false; } if (!isset($this->bevWrite)) { return false; } if (!strlen($data)) { return true; } $this->writing = true; Daemon::$noError = true; if (!$this->bevWrite->write($data) || !Daemon::$noError) { $this->close(); return false; } return true; }