]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/prepend.php
Rename functional for PearDB backend
[SourceForge/phpwiki.git] / lib / prepend.php
1 <?php
2 /* lib/prepend.php
3  *
4  * Things which must be done and defined before anything else.
5  */
6 $RCS_IDS = '';
7 function rcs_id ($id) { $GLOBALS['RCS_IDS'] .= "$id\n"; }
8 rcs_id('$Id: prepend.php,v 1.15 2003-03-07 02:47:32 dairiki Exp $');
9
10 // Used for debugging purposes
11 class DebugTimer {
12     function DebugTimer() {
13         $this->_start = $this->microtime();
14         if (function_exists('posix_times'))
15             $this->_times = posix_times();
16     }
17
18     /**
19      * @param string $which  One of 'real', 'utime', 'stime', 'cutime', 'sutime'
20      * @return float Seconds.
21      */
22     function getTime($which='real', $now=false) {
23         if ($which == 'real')
24             return $this->microtime() - $this->_start;
25
26         if (isset($this->_times)) {
27             if (!$now) $now = posix_times();
28             $ticks = $now[$which] - $this->_times[$which];
29             return $ticks / $this->_CLK_TCK();
30         }
31
32         return 0.0;           // Not available.
33     }
34
35     function getStats() {
36         if (!isset($this->_times)) {
37             // posix_times() not available.
38             return sprintf("real: %.3f", $this->getTime('real'));
39         }
40         $now = posix_times();
41         return sprintf("real: %.3f, user: %.3f, sys: %.3f",
42                        $this->getTime('real'),
43                        $this->getTime('utime', $now),
44                        $this->getTime('stime', $now));
45     }
46         
47     function _CLK_TCK() {
48         // FIXME: this is clearly not always right.
49         // But how to figure out the right value?
50         return 100.0;
51     }
52
53     function microtime(){
54         list($usec, $sec) = explode(" ", microtime());
55         return ((float)$usec + (float)$sec);
56     }
57 }
58 $RUNTIMER = new DebugTimer;
59
60 error_reporting(E_ALL);
61 require_once('lib/ErrorManager.php');
62 require_once('lib/WikiCallback.php');
63
64 // FIXME: deprecated
65 function ExitWiki($errormsg = false)
66 {
67     global $request;
68     static $in_exit = 0;
69
70     if (is_object($request))
71         $request->finish($errormsg); // NORETURN
72
73     if ($in_exit)
74         exit;
75     
76     $in_exit = true;
77
78     global $ErrorManager;
79     $ErrorManager->flushPostponedErrors();
80    
81     if(!empty($errormsg)) {
82         PrintXML(HTML::br(), $errormsg);
83         print "\n</body></html>";
84     }
85     exit;
86 }
87 if (!defined('DEBUG') or (defined('DEBUG') and DEBUG > 2)) {
88   $ErrorManager->setPostponedErrorMask(E_ALL);
89   $ErrorManager->setFatalHandler(new WikiFunctionCb('ExitWiki'));
90 }
91 else 
92 {
93   $ErrorManager->setPostponedErrorMask(E_USER_NOTICE | E_NOTICE);
94 }
95
96
97 // (c-file-style: "gnu")
98 // Local Variables:
99 // mode: php
100 // tab-width: 8
101 // c-basic-offset: 4
102 // c-hanging-comment-ender-p: nil
103 // indent-tabs-mode: nil
104 // End:   
105 ?>