/** * 接続する * @param string $address * @param integer $port * @param integer $timeout * @return boolean */ public function connect($address = null, $port = null, $timeout = null) { if ($this->is_connected()) { throw new \RuntimeException(sprintf("socket has already connected to server [%s:%s]", $this->hotname, $this->port)); } if ($address) { $this->address = $address; } if ($port) { $this->port = $port; } if ($timeout) { $this->timeout = $timeout; } try { $this->_resource_ = fsockopen($this->address, $this->port, $errno, $errstr, $this->timeout); } catch (\Exception $e) { \org\rhaco\Log::error($e->getMessage()); } if (!is_resource($this->_resource_)) { \org\rhaco\Log::error(sprintf("failed to connect server [%s:%s]", $this->address, $this->port)); return false; } return true; }
public function write($message) { try { socket_write($this->socket, $message, strlen($message)); } catch (\Exception $e) { \org\rhaco\Log::warn('Interrupted'); } }
/** * コマンドを実行し出力する * @param string $command 実行するコマンド */ public function write($command) { if (is_resource($this->resource[0])) { \org\rhaco\Log::debug($command); fwrite($this->resource[0], $command . "\n"); } return $this; }
public static function main() { \org\rhaco\Log::info('main'); $obj = new \test\model\TestModelLog(); $obj->run(); foreach (\test\model\TestModel::find(new \org\rhaco\Paginator(1), \org\rhaco\store\db\Q::order('-id')) as $o) { \org\rhaco\Log::info($o->id()); $o->number(100); $o->save(); } $dao = new \test\model\TestModel(); $dao->number(1); $dao->save(); }
/** * @module org.rhaco.Flow * @param mixed $obj */ public function flow_exception_output($obj, \Exception $exception) { \org\rhaco\Log::disable_display(); \org\rhaco\net\http\Header::send('Content-Type', $this->mode == 'jsonp' ? 'text/javascript' : 'application/json'); $error = array('error' => array()); if ($exception instanceof \org\rhaco\Exceptions) { foreach (\org\rhaco\Exceptions::gets() as $g => $e) { $error['error'][] = array('message' => $e->getMessage(), 'group' => $g, 'type' => basename(str_replace("\\", '/', get_class($e)))); } } else { $error['error'][] = array('message' => $exception->getMessage(), 'group' => 'exceptions', 'type' => basename(str_replace("\\", '/', get_class($exception)))); } $json = \org\rhaco\lang\Json::encode($error); print $this->mode == 'jsonp' ? $this->varname . '(' . $json . ')' : $json; }
/** * @module org.rhaco.Flow * @param mixed $obj */ public function flow_exception_output($obj, \Exception $exception) { \org\rhaco\Log::disable_display(); $xml = new \org\rhaco\Xml('error'); if ($exception instanceof \org\rhaco\Exceptions) { foreach (\org\rhaco\Exceptions::gets() as $g => $e) { $message = new \org\rhaco\Xml('message', $e->getMessage()); $message->add('group', $g); $message->add('type', basename(str_replace("\\", '/', get_class($e)))); $xml->add($message); } } else { $message = new \org\rhaco\Xml('message', $exception->getMessage()); $message->add('group', 'exceptions'); $message->add('type', basename(str_replace("\\", '/', get_class($exception)))); $xml->add($message); } $xml->output(); }
/** * 作成 * @param string $package モデル名 * @automap @['post_after'=>['save_and_add_another'=>['do_create','package'],'save'=>['do_find','package']]] */ public function do_create($package) { if ($this->is_post()) { try { $obj = $this->get_model($package, false); $obj->set_props($this); $obj->save(); } catch (\Exception $e) { \org\rhaco\Log::error($e); } } else { $obj = $this->get_model($package, false); } $this->vars('model', $obj); $this->vars('package', $package); }
public function run() { \org\rhaco\Log::info('RUN'); }
<?php \org\rhaco\Log::warn('AAA'); \org\rhaco\Log::warn('BBB');
public function throw_method() { \org\rhaco\Log::disable_display(); throw new \LogicException('error'); }
private function title(\org\rhaco\Log $log) { return $log->time() . ' ' . $log->file() . ':' . $log->line(); }
private function exec($_src_) { /** * 実行前処理 * @param org.rhaco.lang.Str $obj */ $this->object_module('before_exec_template', \org\rhaco\lang\Str::ref($_obj_, $_src_)); foreach ($this->default_vars() as $k => $v) { $this->vars($k, $v); } ob_start(); if (is_array($this->vars) && !empty($this->vars)) { extract($this->vars); } eval('?><?php $_display_exception_=' . (\org\rhaco\Conf::get('display_exception') === true ? 'true' : 'false') . '; ?>' . (string) $_obj_); $_eval_src_ = ob_get_clean(); if (strpos($_eval_src_, 'Parse error: ') !== false) { if (preg_match("/Parse error\\:(.+?) in .+eval\\(\\)\\'d code on line (\\d+)/", $_eval_src_, $match)) { list($msg, $line) = array(trim($match[1]), (int) $match[2]); $lines = explode("\n", $_src_); $plrp = substr_count(implode("\n", array_slice($lines, 0, $line)), "<?php 'PLRP'; ?>\n"); \org\rhaco\Log::error($msg . ' on line ' . ($line - $plrp) . ' [compile]: ' . trim($lines[$line - 1])); $lines = explode("\n", $this->selected_src); \org\rhaco\Log::error($msg . ' on line ' . ($line - $plrp) . ' [plain]: ' . trim($lines[$line - 1 - $plrp])); if (\org\rhaco\Conf::get('display_exception') === true) { $_eval_src_ = $msg . ' on line ' . ($line - $plrp) . ': ' . trim($lines[$line - 1 - $plrp]); } } } $_src_ = $this->selected_src = null; /** * 実行後処理 * @param org.rhaco.lang.Str $obj */ $this->object_module('after_exec_template', \org\rhaco\lang\Str::ref($_obj_, $_eval_src_)); return (string) $_obj_; }