private function traceHttp() { $content = date('Y-m-d H:i:s') . "\nREMOTE_ADDR:" . $_SERVER["REMOTE_ADDR"] . "\nQUERY_STRING:" . $_SERVER["QUERY_STRING"] . "\n\n"; if (isset($_SERVER['HTTP_APPNAME'])) { sae_set_display_errors(FALSE); sae_debug(trim($content)); sae_set_display_errors(TRUE); } else { $max_size = 100000; $log_filename = "log.xml"; if (file_exists($log_filename) and abs(filesize($log_filename)) > $max_size) { unlink($log_filename); } file_put_contents($log_filename, $content, FILE_APPEND); } }
/** * 针对SAE的日志输出,在日志中心中查看,选择debug选项 * @param unknown_type $level * @param unknown_type $message * @param unknown_type $php_error */ public function write_log($level = 'error', $msg, $php_error = FALSE) { if ($this->_enabled === FALSE) { return FALSE; } $level = strtoupper($level); if (!isset($this->_levels[$level]) or $this->_levels[$level] > $this->_threshold) { return FALSE; } if (class_exists('SaeKV')) { sae_set_display_errors(false); // 关闭信息输出 sae_debug($level . ': ' . $msg); //记录日志 sae_set_display_errors(true); // 记录日志后再打开信息输出,否则会阻止正常的错误信息的显示 return TRUE; } else { $filepath = $this->_log_path . 'log-' . date('Y-m-d') . '.php'; $message = ''; if (!file_exists($filepath)) { $message .= "<" . "?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?" . ">\n\n"; } if (!($fp = @fopen($filepath, FOPEN_WRITE_CREATE))) { return FALSE; } $message .= $level . ' ' . ($level == 'INFO' ? ' -' : '-') . ' ' . date($this->_date_fmt) . ' --> ' . $msg . "\n"; flock($fp, LOCK_EX); fwrite($fp, $message); flock($fp, LOCK_UN); fclose($fp); @chmod($filepath, FILE_WRITE_MODE); return TRUE; } }
/** * 日志写入接口 * @access public * @param array $log 日志信息 * @return void */ public function save($log = []) { static $is_debug = null; $now = date($this->config['log_time_format']); // 获取基本信息 if (isset($_SERVER['HTTP_HOST'])) { $current_uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; } else { $current_uri = "cmd:" . implode(' ', $_SERVER['argv']); } $runtime = number_format(microtime(true) - START_TIME, 6); $reqs = number_format(1 / $runtime, 2); $time_str = " [运行时间:{$runtime}s] [吞吐率:{$reqs}req/s]"; $memory_use = number_format((memory_get_usage() - START_MEM) / 1024, 2); $memory_str = " [内存消耗:{$memory_use}kb]"; $file_load = " [文件加载:" . count(get_included_files()) . "]"; array_unshift($log, ['type' => 'log', 'msg' => $current_uri . $time_str . $memory_str . $file_load]); $info = ''; foreach ($log as $line) { $info .= '[' . $line['type'] . '] ' . $line['msg'] . "\r\n"; } $logstr = "[{$now}] {$_SERVER['SERVER_ADDR']} {$_SERVER['REMOTE_ADDR']} {$_SERVER['REQUEST_URI']}\r\n{$info}\r\n"; if (is_null($is_debug)) { preg_replace('@(\\w+)\\=([^;]*)@e', '$appSettings[\'\\1\']="\\2";', $_SERVER['HTTP_APPCOOKIE']); $is_debug = in_array($_SERVER['HTTP_APPVERSION'], explode(',', $appSettings['debug'])) ? true : false; } if ($is_debug) { sae_set_display_errors(false); //记录日志不将日志打印出来 } sae_debug($logstr); if ($is_debug) { sae_set_display_errors(true); } }
function PrintErrorMsg($ErrCode, $ErrMsg) { // $content = date('Y-m-d H:i:s'). "\nERROR_CODE: ". $ErrCode . "\nERROR_MSG: " .$ErrMsg; // $log_filename = "log.xml"; // file_put_contents($log_filename,$content,FILE_APPEND); sae_debug("ErrCode : " . $ErrCode . " ErrMsg : " . $ErrMsg); }
public function fatal($message) { $level = "FATAL"; $log_msg = "[" . $this->p_name . "]\t" . $level . "\t" . $message; sae_set_display_errors(false); sae_debug($log_msg); sae_set_display_errors(true); }
/** * Index * * The Front Controller for handling every request * * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * * Licensed under The MIT License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project * @package app.webroot * @since CakePHP(tm) v 0.2.9 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ function sae_log($msg) { sae_set_display_errors(false); //关闭信息输出 sae_debug($msg); //记录日志 sae_set_display_errors(true); //记录日志后再打开信息输出,否则会阻止正常的错误信息的显示 }
/** * Sends log messages to specified email addresses. * @param array $logs list of log messages */ protected function processLogs($logs) { $message = ''; foreach ($logs as $log) { $message .= $this->formatLogMessage($log[0], $log[1], $log[2], $log[3]); } #$message=wordwrap($message,70); @sae_debug($message); }
public function outputLog() { if (empty($this->logArray)) { return; } sae_set_display_errors(false); //关闭网页输出 foreach ($this->logArray as $logItem) { // 采用 sae_debug 输出日志 sae_debug('[' . $logItem['level'] . '][' . $logItem['source'] . '][' . trim($logItem['msg']) . ']'); } }
function dlog($log, $type = 'log', $css = '') { $log_file = AROOT . 'compiled' . DS . 'log.txt'; if (is_array($log)) { $log = print_r($log, true); } if (is_writable($log_file)) { file_put_contents($log_file, $log . '@' . time() . PHP_EOL, FILE_APPEND); } elseif (on_sae()) { sae_debug($log); } }
function writelog_debug($msg) { sae_set_display_errors(false); //关闭信息输出 if (is_array($msg)) { $msg = implode(",", $msg); } sae_debug("[abcabc]" . $msg); //记录日志 sae_set_display_errors(true); //记录日志后再打开信息输出,否则会阻止正常的错误信息的显示 }
protected static function mq($query) { // return $query; $sae = self::get_sae(); $sae->runSql($query); if ($sae->errno() != 0) { $errormsg = $sae->errmsg(); sae_debug($errormsg); return "Error:" . $errormsg; // die( "Error:" . $errormsg); } $lastId = $sae->lastId(); $sae->closeDb(); return $lastId; }
protected function write(array $record) { if (null === $this->stream) { if (!$this->url) { throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().'); } $this->errorMessage = null; set_error_handler(array($this, 'customErrorHandler')); sae_set_display_errors(false); //关闭信息输出 sae_debug((string) $record['formatted']); //记录日志 sae_set_display_errors(true); restore_error_handler(); } }
function ImpoLogger($log_content) { if (isset($_SERVER['HTTP_APPNAME'])) { //SAE sae_set_display_errors(false); sae_debug($log_content); sae_set_display_errors(true); } else { //LOCAL $max_size = 500000; $log_filename = './log/impo/' . date('Y-m-d') . 'impolog.xml'; if (file_exists($log_filename) and abs(filesize($log_filename)) > $max_size) { unlink($log_filename); } file_put_contents($log_filename, date('Y-m-d H:i:s') . $log_content . "\n", FILE_APPEND); } }
/** * 日志写入接口 * @access public * @param string $log 日志信息 * @param string $destination 写入目标 * @return void */ public function write($log, $destination = '') { static $is_debug = null; $now = date($this->config['log_time_format']); $logstr = "[{$now}] " . $_SERVER['REMOTE_ADDR'] . ' ' . $_SERVER['REQUEST_URI'] . "\r\n{$log}\r\n"; if (is_null($is_debug)) { preg_replace('@(\\w+)\\=([^;]*)@e', '$appSettings[\'\\1\']="\\2";', $_SERVER['HTTP_APPCOOKIE']); $is_debug = in_array($_SERVER['HTTP_APPVERSION'], explode(',', $appSettings['debug'])) ? true : false; } if ($is_debug) { sae_set_display_errors(false); } //记录日志不将日志打印出来 sae_debug($logstr); if ($is_debug) { sae_set_display_errors(true); } }
/** * Write Log File * * Support Sina App Engine * * @param string $msg Message * @param string $level Log level * @return void */ protected static function write($msg, $level = '') { if (Config::getSoul()->APP_DEBUG == false) { return; } if (function_exists('saeAutoLoader')) { $msg = "[{$level}]" . $msg; sae_set_display_errors(false); sae_debug(trim($msg)); sae_set_display_errors(true); } else { $msg = date('[ Y-m-d H:i:s ]') . "[{$level}]" . $msg . "\r\n"; $logPath = Config::getSoul()->APP_FULL_PATH . '/logs'; if (!file_exists($logPath)) { Helper::mkdirs($logPath); } file_put_contents($logPath . '/' . date('Ymd') . '.log', $msg, FILE_APPEND); } }
public function writeTo($str) { if (DAGGER_PLATFORM == 'sae') { if ($this->location == 'log') { ini_set("display_errors", "Off"); sae_debug($str); ini_set("display_errors", "On"); } else { throw new BaseModelException("SAE不支持追加写入功能", 90900, 'file_trace'); } } else { $dirName = dirname($this->path); BaseModelCommon::recursiveMkdir($dirName); $fp = fopen($this->path, "a"); $num = fwrite($fp, $str); fclose($fp); return $num; } }
private function checkSignature() { $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = TOKEN; // sae_debug($token); $tmpArr = array($token, $timestamp, $nonce); sort($tmpArr, SORT_STRING); $tmpStr = implode($tmpArr); $tmpStr = sha1($tmpStr); sae_debug("tempstr : " . $tmpStr); sae_debug("signature: " . $signature); if ($tmpStr == $signature) { //echo $_GET["echostr"]; return true; } else { return false; } }
public static function real_write($s, $file = 'phperror.php') { if (IN_SAE) { sae_set_display_errors(false); sae_debug($s); return TRUE; } $logpath = FRAMEWORK_LOG_PATH; $logfile = $logpath . $file; try { $fp = fopen($logfile, 'ab+'); if (!$fp) { throw new Exception('写入日志失败,可能磁盘已满,或者文件' . $logfile . '不可写。'); } fwrite($fp, $s); fclose($fp); } catch (Exception $e) { } return TRUE; }
function logger2($log_content) { if (isset($_SERVER['HTTP_BAE_ENV_APPID'])) { //BAE require_once "BaeLog.class.php"; $logger = BaeLog::getInstance(); $logger->logDebug($log_content); } else { if (isset($_SERVER['HTTP_APPNAME'])) { //SAE sae_set_display_errors(false); sae_debug($log_content); sae_set_display_errors(true); } else { $max_size = 100000; $log_filename = "log.xml"; if (file_exists($log_filename) and abs(filesize($log_filename)) > $max_size) { unlink($log_filename); } file_put_contents($log_filename, date('H:i:s') . " " . $log_content . "\r\n", FILE_APPEND); } } }
function log_write($log) { static $is_debug = null; if (is_null($is_debug)) { preg_replace('@(\\w+)\\=([^;]*)@e', '$appSettings[\'\\1\']="\\2";', $_SERVER['HTTP_APPCOOKIE']); $is_debug = in_array($_SERVER['HTTP_APPVERSION'], explode(',', $appSettings['debug'])) ? true : false; } if ($is_debug) { sae_set_display_errors(false); } //记录日志不将日志打印出来 sae_debug($log); if ($is_debug) { sae_set_display_errors(true); } }
private function logger($log_content) { if (isset($_SERVER['HTTP_APPNAME'])) { //SAE sae_set_display_errors(false); sae_debug($log_content); sae_set_display_errors(true); } else { if ($_SERVER['REMOTE_ADDR'] != "127.0.0.1") { //LOCAL $max_size = 10000; $log_filename = "log.xml"; if (file_exists($log_filename) and abs(filesize($log_filename)) > $max_size) { unlink($log_filename); } file_put_contents($log_filename, date('H:i:s') . " " . $log_content . "\r\n", FILE_APPEND); } } }
public function tq_test2() { sae_debug("列队任务2被执行,k1的值:{$_POST['k1']},k2的值:{$_POST['k2']}"); //在本地请查看日志:App\Runtime\Logs\sae_debug.log }
} } curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); // grab URL and pass it to the browser sae_debug('client headers:' . var_export($headers, true) . "\n"); sae_debug('starting curl request' . "\n"); sae_debug($post_data . "\n"); $result = curl_exec($ch); curl_close($ch); sae_debug('finished curl request' . "\n"); sae_debug('response:' . var_export($result, true) . "\n"); //we only handle 1 response no redirects $result = explode("\r\n\r\n", $result, 2); //we neeed to split up the ehaders $result_headers = explode("\r\n", $result[0]); //now echo out the same headers the server passed to us sae_debug("setting headers\n"); foreach ($result_headers as &$header) { if (substr_count($header, 'Set-Cookie:') == 0) { header($header); } } header('Content-Length: ' . strlen($result[1])); header('Connection: close'); // now echo out the body sae_debug("sending body\n"); echo $result[1]; ob_end_flush(); sae_debug("done\n"); die; // close cURL resource, and free up system resources
public static function SetLastError($info) { $error = $info; sae_debug($info); }
public function SendVideo($openId, $videoArray) { // thumb_media_id : not option! $access_token = get_Access_Token(); $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" . $access_token; $data = '{ "touser":"******", "msgtype":"video", "video": { "title":"' . $videoArray['Title'] . '", "description":"' . $videoArray['Description'] . '", "media_id":"' . $videoArray['Media_id'] . '" } }'; $ret = https_request($url, $data); var_dump($ret); sae_debug($ret); }
static function SmtpMail($from, $to, $subject, $message, $options = null, $bcc = array()) { /* settings */ if (!isset($options['subjectenc'])) { $options['subjectenc'] = 'UTF-8'; } if (!isset($options['encoding'])) { $options['encoding'] = 'UTF-8'; } if (!isset($options['contentType'])) { $options['contentType'] = 'text/plain'; } if ('UTF-8' != $options['encoding']) { $message = mb_convert_encoding($message, $options['encoding'], 'UTF-8'); } global $INI; /* get from ini */ $host = $INI['mail']['host']; $port = $INI['mail']['port']; $ssl = $INI['mail']['ssl']; $user = $INI['mail']['user']; $pass = $INI['mail']['pass']; $from = $INI['mail']['from']; $reply = $INI['mail']['reply']; $site = $INI['system']['sitename']; //SAE 邮件发送 $ishtml = $options['contentType'] == 'text/html'; if ($ishtml) { $ContentType = 'HTML'; } else { $ContentType = 'TEXT'; } $options = array('to' => $to, 'subject' => $subject, 'content' => $message, 'content_type' => $ContentType, 'smtp_username' => $user, 'smtp_password' => $pass, 'from' => $from); $mail = new SaeMail($options); $ret = $mail->Send(); //发送失败时输出错误码和错误信息 if ($ret === false) { sae_debug($mail->errmsg()); } $mail->clean(); return $ret; /* $subject = self::EscapeHead($subject, $options['subjectenc']); $site = self::EscapeHead($site, $options['subjectenc']); $body = $message; $ishtml = ($options['contentType']=='text/html'); //begin $mail = new PHPMailer(); $mail->IsSMTP(); $mail->CharSet = $options['encoding']; $mail->SMTPAuth = true; $mail->Host = $host; $mail->Port = $port; if ( $ssl=='ssl' ) { $mail->SMTPSecure = "ssl"; } else if ( $ssl == 'tls' ) { $mail->SMTPSecure = "tls"; } $mail->Username = $user; $mail->Password = $pass; $mail->SetFrom($from, $site); $mail->AddReplyTo($reply, $site); foreach($bcc AS $bo) { $mail->AddBCC($bo); } $mail->Subject = $subject; if ( $ishtml ) { $mail->MsgHTML($body); } else { $mail->Body = $body; } $mail->AddAddress($to); return $mail->Send(); */ }
static function write($message, $level = self::ERR, $type = '', $destination = '', $extra = '') { self::sae_set_display_errors(false); sae_debug('###' . $_SERVER['REQUEST_URI'] . " | {$level}: {$message}###"); self::sae_set_display_errors(true); //clearstatcache(); }
/** * {@inheritdoc} */ protected function write(array $record) { sae_debug((string) $record['formatted']); }
static function show_upload_topic($pic) { define('TEMP', 'topic'); //要上传的缓存storage名称定义 $s = new SaeStorage(); $picname = $_FILES[$pic]['name']; $picsize = $_FILES[$pic]['size']; if ($picname != "") { if ($picsize > 5120000) { echo '图片大小不能超过2M'; exit; } $type = strstr($picname, '.'); if ($type != ".gif" && $type != ".jpg" && $type != ".png" && $type != ".jpeg") { echo '图片格式不对!只支持jpg,png,gif'; exit; } if (!$_FILES[$pic]['name']) { die('没有选择文件!'); } //上传文件校验,可以添加文件类型等检验、此处简略处理 $file_name = "topic_" . time() . rand(100, 999); //定义保存的文件名称 $ext = end(explode('.', $_FILES[$pic]['name'])); //获得扩展名 $pic_path = $file_name . '.' . $ext; //要保存的文件路径+文件名,此处保存在upload/目录下 if ($s->upload(TEMP, $pic_path, $_FILES[$pic]['tmp_name'])) { //裁成三种大小 $poc = array(array(200, 200, '_big.jpg'), array(64, 64, '_midde.jpg'), array(22, 22, '_small.jpg')); //将图片剪裁之后存入storage foreach ($poc as $p) { $pict = $file_name . $p[2]; $data = self::clip_topic($p[0], $p[1], $pic_path, "center", TEMP); $url = $s->write(TEMP, $pict, $data); if ($url == FALSE) { die('图片剪裁写入失败!'); } $pics[] = $url; unset($data); unset($pict); } //如果不是jpg格式则重新写入jpg格式 if ($ext != 'jpg') { $data = $s->read(TEMP, $pic_path); if (!$s->write(TEMP, $file_name . '.jpg', $data)) { die('图片写入失败!'); } } //获取三个图片地址 $pics_b = $pics[0]; $pics_m = $pics[1]; $pics_s = $pics[2]; } else { $emsg = '上传零时文件失败' . $s->errmsg(); sae_debug($emsg); die($emsg); } //将三种地址放入数组输出 $out_pic = array('pic_name' => array($file_name, $ext), 'pic_url' => array($pics_b, $pics_m, $pics_s)); return $out_pic; } }
<?php //sae_debug("in oath2/callback!!!!"); require '../../lib.php'; $ret = array('ret' => 0, 'msg' => '成功'); $oauth = OpenHelper::oauthCompany(); //默认会从Get参数中拿到code去获得companyToken $result = $oauth->getCompanyToken(); if (OpenConfig::SAE_MODE) { $s = new SaeStorage(); $s->upload(OpenConfig::SAE_DOMAIN, 'data.dat', '../../data.dat'); } if ($result['ret'] == 0 && !empty($result['data'])) { $company_token = $result['data']; $company_token['status'] = 0; saveToken($company_token); } else { $ret['ret'] = 1; $ret['msg'] = '失败'; } if (OpenConfig::SAE_MODE) { ini_set('display_errors', 0); sae_debug(json_encode($ret)); ini_set('display_errors', 1); } OpenUtils::outputJson($ret);