PHP的debug技术
给程序加上debug函数,来记录其他代码的结果, DEBUG为开关。 代码来源:wp-global-translator-plugin。
1 2 3 4 5 6 7 8 9 10 11 | function debug($msg) { if (DEBUG) { $today = date("Y-m-d H:i:s "); $myFile = dirname(__file__) . "/debug.log"; $fh = fopen($myFile, 'a') or die("Can't open debug file. Please manually create the 'debug.log' file (inside the 'global-translator' directory) and make it writable."); $ua_simple = preg_replace("/(.*)\s\(.*/","\\1",$_SERVER['HTTP_USER_AGENT']); fwrite($fh, $today . " [from: ".$_SERVER['REMOTE_ADDR']."|$ua_simple] - " . $msg . "\n"); fclose($fh); } } |
在程序的其他部分,需要时加上debug("")记录结果,如下面求当前URI的散列表现:$hash。
1 2 3 4 5 6 7 8 9 10 11 | function gltr_get_page_content($lang, $url) { $page = ''; if (USE_CACHE) { $refresh = CACHE_TIMEOUT; $req = preg_replace('/(.*)\/$/', '\\1', $_SERVER['REQUEST_URI']); $req = preg_replace('/#.*$/', '', $req); $hash = str_replace(array('?','<','>',':','\\','/','*','|','"'), '_', $req); debug("Hashing uri: $req to: $hash"); ....... |
| -欢迎为本文评级 |
No donations within the last 180 days.Who make donation will leave message at here.Donate Now.
This a wordpress plugin Wp-Donators.It provides a smart donation function to autoleave the sponsor information in this container after payment. People can donate and submit name/URL or TextLink AD. The information of the latest donors are displayed in the cloud. The more a person donates, the bigger their link will be.It's will support most popular payment interface in future. ParPal Just the first one. More..
Powered By:WP-DONATORS
相关日志 |
本文读者也关心以下内容:
|















































Leave a reply