예제 #1
0
 function exception(Exception $e)
 {
     logger::emerg("Unhandled exception: (%s) %s in %s:%d", get_class($e), $e->getMessage(), str_replace(BASE_PATH, '', $e->getFile()), $e->getLine());
     Console::debugEx(0, get_class($e), "Unhandled exception: (%s) %s in %s:%d", get_class($e), $e->getMessage(), str_replace(BASE_PATH, '', $e->getFile()), $e->getLine());
     $f = file($e->getFile());
     foreach ($f as $i => $line) {
         $mark = $i + 1 == $e->getLine() ? '=> ' : '   ';
         $f[$i] = sprintf('  %05d. %s', $i + 1, $mark) . $f[$i];
         $f[$i] = str_replace("\n", "", $f[$i]);
     }
     $first = $e->getLine() - 4;
     if ($first < 0) {
         $first = 0;
     }
     $last = $e->getLine() + 3;
     if ($last >= count($f)) {
         $last = count($f) - 1;
     }
     $source = join("\n", array_slice($f, $first, $last - $first));
     Console::debugEx(0, get_class($e), Console::backtrace(0, $e->getTrace(), true));
     Console::debugEx(LOG_LOG, "Exception", "Source dump of %s:\n%s", str_replace(BASE_PATH, '', $e->getFile()), $source);
     $rv = 1;
     logger::emerg("Exiting with return code %d after exception.", $rv);
     Console::debugEx(LOG_BASIC, __CLASS__, "Exiting with return code %d after exception.", $rv);
 }
예제 #2
0
 function exception(Exception $e)
 {
     if (ob_get_length() != false) {
         @ob_end_clean();
     }
     $et = typeOf($e);
     if ($et == 'FileNotFoundException' || $et == 'NavigationException') {
         response::setStatus(404);
         header('HTTP/1.1 404 Not Found', true);
         printf("<h1>404: Not Found</h1>");
         return;
     }
     if ($et == 'HttpException') {
         response::setStatus($e->getCode());
         $code = $e->getMessage();
         list($code) = explode(':', $code);
         $code = str_replace('Error ', '', $code);
         $msg = HttpException::getHttpMessage($code);
         header('HTTP/1.1 ' . $code . ' ' . $msg . ' ' . $msg);
         printf("<h1>%s: %s</h1>\n<pre>%s</pre>", $code, $msg, $msg);
         return;
     }
     response::setStatus(500);
     logger::emerg("Unhandled exception: (%s) %s in %s:%d", get_class($e), $e->getMessage(), str_replace(BASE_PATH, '', $e->getFile()), $e->getLine());
     header('HTTP/1.1 501 Server Error', true);
     $id = uniqid();
     $dbg = sprintf("Unhandled exception: (%s) %s\n  in %s:%d", get_class($e), $e->getMessage(), str_replace(SYS_PATH, '', $e->getFile()), $e->getLine()) . Console::backtrace(0, $e->getTrace(), true) . "\n" . "Loaded modules:\n" . ModuleManager::debug() . "\n" . request::getDebugInformation();
     logger::emerg($dbg);
     if (config::get('lepton.mvc.exception.log', false) == true) {
         $logfile = config::get('lepton.mvc.exception.logfile', "/tmp/" . $_SERVER['HTTP_HOST'] . "-debug.log");
         $log = "=== Unhandled Exception ===\n\n" . $dbg . "\n";
         $lf = @fopen($logfile, "a+");
         if ($lf) {
             fputs($lf, $log);
             fclose($lf);
         }
     }
     $ico_error = resource::get('warning.png');
     header('content-type: text/html; charset=utf-8');
     echo '<html><head><title>Unhandled Exception</title>' . self::$css . self::$js . '</head><body>' . '<div id="box"><div id="left"><img src="' . $ico_error . '" width="32" height="32"></div><div id="main">' . '<h1>An Unhandled Exception Occured</h1>' . '<hr noshade>' . '<p>This means that something didn\'t go quite go as planned. This could be ' . 'caused by one of several reasons, so please be patient and try ' . 'again in a little while.</p>';
     if (config::get('lepton.mvc.exception.feedback', false) == true) {
         echo '<p>The administrator of the website has been notified about this error. You ' . 'can help us find and fix the problem by writing a line or two about what you were doing when this ' . 'error occured.</p>';
         echo '<p id="feedbacklink"><a href="javascript:doFeedback();">If you would like to assist us with more information, please click here</a>.</p>';
         echo '<div id="feedback" style="display:none;"><p>Describe in a few short lines what you were doing right before you encountered this error:</p><form action="/errorevent.feedback/' . $id . '" method="post"><div><textarea name="text" style="width:100%; height:50px;"></textarea></div><div style="padding-top:5px; text-align:right;"><input type="button" value=" Close " onclick="closeFeedback();"> <input type="submit" value=" Submit Feedback "></div></form></div>';
     }
     if (config::get('lepton.mvc.exception.showdebug', false) == true) {
         echo '<hr noshade>' . '<a href="javascript:toggleAdvanced();">Details &raquo;</a>' . '<pre id="advanced" style="display:none; height:300px;">' . $dbg . '</pre>';
     }
     echo '<div>' . '</body></html>';
 }
예제 #3
0
파일: proc.php 프로젝트: sss201413/ecstore
 /**
  * 多进程执行队列
  *
  * @param string $queue_name
  * @param int $max
  * @param string $phpExec
  */
 public function exec($queue_name, $max, $phpExec = '')
 {
     $max = $max ? $max : 1;
     $time = time();
     while (1) {
         //执行死循环
         try {
             while ($this->threadRunning < $max && !system_queue::instance()->is_end($queue_name)) {
                 $this->running[] = new system_queue_consumer_proc_thread($queue_name, $phpExec);
                 usleep(200000);
                 $this->threadRunning++;
             }
         } catch (Exception $e) {
             switch ($e->getCode()) {
                 case 30001:
                     logger::emerg(sprintf('ERROR:%d @ %s', $e->getCode(), $e->getMessage));
                     exit;
             }
         }
         //检查是否已经结束
         if ($this->threadRunning == 0) {
             break;
         }
         //等待代码执行完成
         usleep(50000);
         $thread_close = array();
         //记录线程的关闭状态
         //检查已经完成的任务
         foreach ($this->running as $idx => $thread) {
             if (!$thread->isRunning() || $thread->isOverExecuted($max)) {
                 $thread_close[] = proc_close($thread->resource);
                 //记录线程的关闭状态
                 unset($this->running[$idx]);
                 $this->threadRunning--;
             }
         }
     }
 }
예제 #4
0
파일: settag.php 프로젝트: 453111208/bbc
 function main()
 {
     $tagctl = app::get('desktop')->model('tag');
     $tag_rel = app::get('desktop')->model('tag_rel');
     $tag_name = $_POST['tag']['name'];
     $tag_stat = $_POST['tag']['stat'];
     $tag_ids = $_POST['tag']['tag_id'];
     if ($_POST['filter']) {
         $obj = $this->object;
         $schema = $obj->get_schema();
         $idColumn = $schema['idColumn'];
         $filter = unserialize($_POST['filter']);
         logger::emerg('---zz' . var_export($filter, true));
         $rows = $obj->getList($idColumn, $filter, 0, -1);
         foreach ($rows as $value) {
             $pkey[] = $value[$idColumn];
         }
     }
     $pkey = (array) $pkey;
     //没有选择任何标签情况 time:2010-11-24
     if (!$tag_stat || !is_array($tag_stat)) {
         header('Content-Type:application/json; charset=utf-8');
         echo '{error:"' . app::get('desktop')->_('标签设置失败!') . '"}';
         exit;
     }
     foreach ($tag_stat as $key => $value) {
         if ($value == 2) {
             continue;
         }
         if ($value == 1) {
             //取消标签
             $tag_item = $tagctl->getList('tag_id', array('tag_name' => $tag_name[$key], 'tag_type' => $this->object->table_name()));
             foreach ($pkey as $id) {
                 if (!intval($id) && !intval($tag_item[0]['tag_id'])) {
                     continue;
                 }
                 $tag_rel->delete(array('tag_id' => $tag_item[0]['tag_id'], 'rel_id' => $id));
             }
         } else {
             //设置标签
             $tag_item = $tagctl->getList('tag_id', array('tag_name' => $tag_name[$key], 'tag_type' => $this->object->table_name()));
             if ($tag_item && !$tag_ids[$key]) {
                 header('Content-Type:application/json; charset=utf-8');
                 echo '{error:"' . app::get('desktop')->_('标签重复添加!') . '",_:null}';
                 exit;
             }
             $data['tag_type'] = $this->object->table_name();
             $data['tag_name'] = $tag_name[$key];
             $data['app_id'] = $this->app->app_id;
             $tagctl->save($data);
             logger::emerg('---' . var_export($data, true));
             logger::emerg('---xx' . var_export($pkey, true));
             if ($data['tag_id']) {
                 $data2['tag']['tag_id'] = $data['tag_id'];
                 unset($data['tag_id']);
                 foreach ($pkey as $id) {
                     $data2['tag_type'] = $this->object->table_name();
                     $data2['app_id'] = $this->app->app_id;
                     $data2['rel_id'] = $id;
                     //save修改了data tag_id的位置 edit by jiaolei time:2010-11-17 mantis:0019313
                     $data2['tag']['tag_id'] or $data2['tag']['tag_id'] = $data2['tag_id'];
                     logger::emerg("===" . var_export($data2, true));
                     $tag_rel->save($data2);
                 }
             }
         }
     }
     //header('Content-Type:application/json; charset=utf-8');
     $res['success'] = app::get('desktop')->_('标签设置成功');
     return response::json($res);
 }
예제 #5
0
 /**
  * @static
  * @param bool $playNice
  * @return bool
  */
 public static function stopFrontendCrawler($playNice = true, $isFrontendCall = false)
 {
     logger::debug("SearchPhp_Plugin: forcing frontend crawler stop, play nice: [ {$playNice} ]");
     self::setStopLock("frontend", true);
     //just to make sure nothing else starts the crawler right now
     self::setCrawlerState("frontend", "started", false);
     $configArray = self::getSearchConfigArray();
     $maxThreads = $configArray['search']['frontend']['crawler']['maxThreads'];
     $db = Pimcore_Resource_Mysql::get();
     $db->query("DROP TABLE IF EXISTS `plugin_searchphp_frontend_crawler_todo`;");
     $db->query("DROP TABLE IF EXISTS `plugin_searchphp_indexer_todo`;");
     logger::debug("SearchPhp_Plugin: forcing frontend crawler stop - dropped tables");
     sleep(1);
     $pidFiles = array("maintainance_crawler-indexer");
     for ($i = 1; $i <= $maxThreads; $i++) {
         $pidFiles[] = "maintainance_crawler-" . $i;
     }
     $counter = 1;
     while ($pidFiles and count($pidFiles) > 0 and $counter < 10) {
         sort($pidFiles);
         for ($i = 0; $i < count($pidFiles); $i++) {
             $file = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . $pidFiles[$i];
             if (!is_file($file)) {
                 unset($pidFiles[$i]);
             }
         }
         sleep(1);
         $counter++;
     }
     if (!$playNice) {
         if (is_file(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/maintainance_SearchPhp_Plugin.pid" and $isFrontendCall)) {
             $pidFiles[] = "maintainance_SearchPhp_Plugin.pid";
         }
         //delete pid files of all  processes
         for ($i = 0; $i < count($pidFiles); $i++) {
             $file = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . $pidFiles[$i];
             if (is_file($file) and !unlink($file)) {
                 logger::emerg("SearchPhp_Plugin: : Trying to force stop crawler, but cannot delete [ {$file} ]");
             }
             if (!is_file($file)) {
                 unset($pidFiles[$i]);
             }
         }
     }
     self::setStopLock("frontend", false);
     if (!$pidFiles or count($pidFiles) == 0) {
         self::setCrawlerState("frontend", "finished", false);
         return true;
     }
     return false;
 }
예제 #6
0
 /**
  * @return void
  */
 public static function generateSitemap()
 {
     $sitemapDir = PIMCORE_WEBSITE_PATH . "/var/search/sitemap";
     if (is_dir($sitemapDir) and !is_writable($sitemapDir)) {
         $sitemapDirAvailable = false;
     } else {
         if (!is_dir($sitemapDir)) {
             $sitemapDirAvailable = mkdir($sitemapDir, 0755, true);
             chmod($sitemapDir, 0755);
         } else {
             $sitemapDirAvailable = true;
         }
     }
     if ($sitemapDirAvailable) {
         $db = Pimcore_Resource_Mysql::get();
         $hosts = $db->fetchAll("SELECT DISTINCT host from plugin_searchphp_contents");
         if (is_array($hosts)) {
             //create domain sitemaps
             foreach ($hosts as $row) {
                 $host = $row['host'];
                 $data = $db->fetchAll("SELECT * FROM plugin_searchphp_contents WHERE host = '" . $host . "' AND content != 'canonical' AND content!='noindex' ORDER BY uri", array());
                 $name = str_replace(".", "-", $host);
                 $filePath = $sitemapDir . "/sitemap-" . $name . ".xml";
                 $fh = fopen($filePath, 'w');
                 fwrite($fh, '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n");
                 fwrite($fh, '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
                 fwrite($fh, "\r\n");
                 foreach ($data as $row) {
                     $uri = str_replace("&pimcore_outputfilters_disabled=1", "", $row['uri']);
                     $uri = str_replace("?pimcore_outputfilters_disabled=1", "", $uri);
                     fwrite($fh, '<url>' . "\r\n");
                     fwrite($fh, '    <loc>' . htmlspecialchars($uri, ENT_QUOTES) . '</loc>' . "\r\n");
                     fwrite($fh, '</url>' . "\r\n");
                 }
                 fwrite($fh, '</urlset>' . "\r\n");
                 fclose($fh);
             }
             //create sitemap index file
             $filePath = $sitemapDir . "/sitemap.xml";
             $fh = fopen($filePath, 'w');
             fwrite($fh, '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n");
             fwrite($fh, '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
             fwrite($fh, "\r\n");
             foreach ($hosts as $row) {
                 $host = $row['host'];
                 $name = str_replace(".", "-", $host);
                 //first host must be main domain - see hint in plugin settings
                 $currenthost = $hosts[0]['host'];
                 fwrite($fh, '<sitemap>' . "\r\n");
                 fwrite($fh, '    <loc>http://' . $currenthost . "/plugin/SearchPhp/frontend/sitemap/?sitemap=sitemap-" . $name . ".xml" . '</loc>' . "\r\n");
                 fwrite($fh, '</sitemap>' . "\r\n");
             }
             fwrite($fh, '</sitemapindex>' . "\r\n");
             fclose($fh);
         } else {
             logger::warn("SearchPhp_Tool: could not generate sitemaps, did not find any hosts in index.");
         }
     } else {
         logger::emerg("SearchPhp_Tool: Cannot generate sitemap. Sitemap directory [ " . $sitemapDir . " ]  not available/not writeable and cannot be created");
     }
 }