日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

使用日志记录功能查看PHP扩展的执行过程

發(fā)布時(shí)間:2025/4/9 php 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用日志记录功能查看PHP扩展的执行过程 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

了解過PHP內(nèi)核的同學(xué)都知道,PHP的一次請求的生命周期

1.啟動(dòng)Apache后,PHP解釋程序也隨之啟動(dòng)。PHP調(diào)用各個(gè)擴(kuò)展的MINIT方法,從而使這些擴(kuò)展切換到可用狀態(tài)

2.當(dāng)一個(gè)頁面請求發(fā)生時(shí),SAPI層將控制權(quán)交給PHP層。于是PHP設(shè)置了用于回復(fù)本次請求所需的環(huán)境變量。同時(shí),它還建立一個(gè)變量表,用來存放執(zhí)行過程 中產(chǎn)生的變量名和值。PHP調(diào)用各個(gè)模塊的RINIT方法,即“請求初始化”。RINIT方法可以看作是一個(gè)準(zhǔn)備過程, 在程序執(zhí)行之間就會自動(dòng)啟動(dòng)

3.如同PHP啟動(dòng)一樣,PHP的關(guān)閉也分兩步。一旦頁面執(zhí)行完畢(無論是執(zhí)行到了文件末尾還是用exit或die函數(shù)中止),PHP就會啟動(dòng)清理程序。它會按順序調(diào)用各個(gè)模塊的RSHUTDOWN方法。 RSHUTDOWN用以清除程序運(yùn)行時(shí)產(chǎn)生的符號表,也就是對每個(gè)變量調(diào)用unset函數(shù)。

4.最后,所有的請求都已處理完畢,SAPI也準(zhǔn)備關(guān)閉了,PHP開始執(zhí)行第二步:PHP調(diào)用每個(gè)擴(kuò)展的MSHUTDOWN方法,這是各個(gè)模塊最后一次釋放內(nèi)存的機(jī)會

以上是運(yùn)行在Apache服務(wù)中,而Nginx+FastCgi似乎不是這樣,這一點(diǎn)我會后期深究,今天主要探討日志功能,便也后期學(xué)習(xí)


?

首先我們按照我的這篇博文(在Linux下編寫php擴(kuò)展)生成一個(gè)擴(kuò)展

然后我們在myext.c文件中添加一個(gè)日志函數(shù),然后分別在

PHP_MINIT_FUNCTION,PHP_MSHUTDOWN_FUNCTION,PHP_RINIT_FUNCTION,PHP_RSHUTDOWN_FUNCTION四個(gè)函數(shù)中添加調(diào)用日志的函數(shù)

然后編譯擴(kuò)展,重新服務(wù),允許等操作,看看是否有日志

?

下面我給出一個(gè)完整的文件?

?

1 /* 2 +----------------------------------------------------------------------+ 3 | PHP Version 5 | 4 +----------------------------------------------------------------------+ 5 | Copyright (c) 1997-2016 The PHP Group | 6 +----------------------------------------------------------------------+ 7 | This source file is subject to version 3.01 of the PHP license, | 8 | that is bundled with this package in the file LICENSE, and is | 9 | available through the world-wide-web at the following url: | 10 | http://www.php.net/license/3_01.txt | 11 | If you did not receive a copy of the PHP license and are unable to | 12 | obtain it through the world-wide-web, please send a note to | 13 | license@php.net so we can mail you a copy immediately. | 14 +----------------------------------------------------------------------+ 15 | Author: | 16 +----------------------------------------------------------------------+ 17 */ 18 19 /* $Id$ */ 20 21 #ifdef HAVE_CONFIG_H 22 #include "config.h" 23 #endif 24 25 #include "php.h" 26 #include "php_ini.h" 27 #include "ext/standard/info.h" 28 #include "php_myext.h" 29 30 /* If you declare any globals in php_myext.h uncomment this: 31 ZEND_DECLARE_MODULE_GLOBALS(myext) 32 */ 33 34 /* True global resources - no need for thread safety here */ 35 static int le_myext; 36 void save_log(); 37 /* {{{ PHP_INI 38 */ 39 /* Remove comments and fill if you need to have entries in php.ini 40 PHP_INI_BEGIN() 41 STD_PHP_INI_ENTRY("myext.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_myext_globals, myext_globals) 42 STD_PHP_INI_ENTRY("myext.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_myext_globals, myext_globals) 43 PHP_INI_END() 44 */ 45 /* }}} */ 46 47 /* Remove the following function when you have successfully modified config.m4 48 so that your module can be compiled into PHP, it exists only for testing 49 purposes. */ 50 51 /* Every user-visible function in PHP should document itself in the source */ 52 /* {{{ proto string confirm_myext_compiled(string arg) 53 Return a string to confirm that the module is compiled in */ 54 PHP_FUNCTION(confirm_myext_compiled) 55 { 56 char *arg = NULL; 57 int arg_len, len; 58 char *strg; 59 60 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { 61 return; 62 } 63 64 len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "myext", arg); 65 RETURN_STRINGL(strg, len, 0); 66 } 67 68 void save_log(char *str) 69 { 70 time_t rawtime; 71 struct tm * timeinfo; 72 time ( &rawtime ); 73 timeinfo = localtime ( &rawtime ); 74 75 char buf[512]; 76 sprintf(buf, "%s", asctime (timeinfo)); 77 78 79 FILE *fp = fopen("/Users/zongshuai/log/c.log", "a+"); 80 ////這里寫一個(gè)絕對路徑,請改成一下,大家還得注意權(quán)限問題,如果發(fā)現(xiàn)打印不出內(nèi)容,檢查一下權(quán)限 81 if (fp==0) { 82 printf("can't open file\n"); 83 return; 84 } 85 86 strcat(str,"\r\n"); 87 88 fseek(fp, 0,SEEK_END); 89 fwrite(buf, strlen(buf) - 1, 1, fp); 90 fwrite(" ", 4, 1, fp); 91 fwrite(str, strlen(str) * sizeof(char), 1, fp); 92 fclose(fp); 93 return; 94 } 95 96 PHP_FUNCTION(sum_two_num) 97 { 98 long x,y,z; 99 100 if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &x,&y) == FAILURE) { 101 RETURN_FALSE; 102 } 103 104 char str[80] = "EXECED MYFUNCTION"; 105 save_log(str); 106 107 z = x * y; 108 109 RETURN_LONG(z); 110 } 111 /* }}} */ 112 /* The previous line is meant for vim and emacs, so it can correctly fold and 113 unfold functions in source code. See the corresponding marks just before 114 function definition, where the functions purpose is also documented. Please 115 follow this convention for the convenience of others editing your code. 116 */ 117 118 119 /* {{{ php_myext_init_globals 120 */ 121 /* Uncomment this function if you have INI entries 122 static void php_myext_init_globals(zend_myext_globals *myext_globals) 123 { 124 myext_globals->global_value = 0; 125 myext_globals->global_string = NULL; 126 } 127 */ 128 /* }}} */ 129 130 /* {{{ PHP_MINIT_FUNCTION 131 */ 132 PHP_MINIT_FUNCTION(myext) 133 { 134 /* If you have INI entries, uncomment these lines 135 REGISTER_INI_ENTRIES(); 136 */ 137 char str[80] = "EXECED PHP_MINIT_FUNCTION"; 138 save_log(str); 139 return SUCCESS; 140 } 141 /* }}} */ 142 143 /* {{{ PHP_MSHUTDOWN_FUNCTION 144 */ 145 PHP_MSHUTDOWN_FUNCTION(myext) 146 { 147 /* uncomment this line if you have INI entries 148 UNREGISTER_INI_ENTRIES(); 149 */ 150 char str[80] = "EXECED PHP_MSHUTDOWN_FUNCTION"; 151 save_log(str); 152 return SUCCESS; 153 } 154 /* }}} */ 155 156 /* Remove if there's nothing to do at request start */ 157 /* {{{ PHP_RINIT_FUNCTION 158 */ 159 PHP_RINIT_FUNCTION(myext) 160 { 161 char str[80] = "EXECED PHP_RINIT_FUNCTION"; 162 save_log(str); 163 return SUCCESS; 164 } 165 /* }}} */ 166 167 /* Remove if there's nothing to do at request end */ 168 /* {{{ PHP_RSHUTDOWN_FUNCTION 169 */ 170 PHP_RSHUTDOWN_FUNCTION(myext) 171 { 172 char str[80] = "EXECED PHP_RSHUTDOWN_FUNCTION"; 173 save_log(str); 174 return SUCCESS; 175 } 176 /* }}} */ 177 178 /* {{{ PHP_MINFO_FUNCTION 179 */ 180 PHP_MINFO_FUNCTION(myext) 181 { 182 php_info_print_table_start(); 183 php_info_print_table_header(2, "myext support", "enabled"); 184 php_info_print_table_end(); 185 186 /* Remove comments if you have entries in php.ini 187 DISPLAY_INI_ENTRIES(); 188 */ 189 } 190 /* }}} */ 191 192 /* {{{ myext_functions[] 193 * 194 * Every user visible function must have an entry in myext_functions[]. 195 */ 196 const zend_function_entry myext_functions[] = { 197 PHP_FE(confirm_myext_compiled, NULL) /* For testing, remove later. */ 198 PHP_FE(sum_two_num, NULL) 199 PHP_FE_END /* Must be the last line in myext_functions[] */ 200 }; 201 /* }}} */ 202 203 /* {{{ myext_module_entry 204 */ 205 zend_module_entry myext_module_entry = { 206 STANDARD_MODULE_HEADER, 207 "myext", 208 myext_functions, 209 PHP_MINIT(myext), 210 PHP_MSHUTDOWN(myext), 211 PHP_RINIT(myext), /* Replace with NULL if there's nothing to do at request start */ 212 PHP_RSHUTDOWN(myext), /* Replace with NULL if there's nothing to do at request end */ 213 PHP_MINFO(myext), 214 PHP_myext_VERSION, 215 STANDARD_MODULE_PROPERTIES 216 }; 217 /* }}} */ 218 219 #ifdef COMPILE_DL_myext 220 ZEND_GET_MODULE(myext) 221 #endif 222 223 /* 224 * Local variables: 225 * tab-width: 4 226 * c-basic-offset: 4 227 * End: 228 * vim600: noet sw=4 ts=4 fdm=marker 229 * vim<600: noet sw=4 ts=4 230 */

?

轉(zhuǎn)載于:https://www.cnblogs.com/xiaozong/p/5823380.html

總結(jié)

以上是生活随笔為你收集整理的使用日志记录功能查看PHP扩展的执行过程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: ass精品国模裸体pics | 开心激情五月网 | 男人网站在线观看 | 国产黄色大片视频 | 成人美女毛片 | 可以直接观看的av | 奇米影视一区二区三区 | 日本大乳奶做爰 | 香蕉视频性 | 国产手机精品视频 | 欧美成人午夜77777 | 韩国一区二区视频 | 欧美一区二区福利视频 | 国产亚洲欧美在线视频 | 欧美8888 | 日韩香蕉网 | 日本在线观看视频网站 | av大片在线看 | 日本一级黄 | 4438x亚洲最大 | www.色婷婷.com| 九九热精品 | 亚洲午夜精品久久久 | 日本特级淫片 | 亚洲欧美一二三 | 五月婷婷在线观看 | 黄色大全在线观看 | 国产日本精品视频 | 99热精品在线播放 | 朝桐光在线视频 | 91精品国产入口在线 | 国产视频分类 | 视色网| 在线看片 | 国产亚洲精品女人久久久久久 | 天堂视频在线免费观看 | 北条麻纪在线观看aⅴ | 日韩七区| 91亚洲成人 | 四虎影院在线免费播放 | 裸体喂奶一级裸片 | 91性生活 | 久久99精品久久久久久水蜜桃 | 精品人人| 日韩不卡av在线 | 男女曰逼视频 | 福利91 | 四虎免费av| 天堂在线资源库 | 国产精品一二三四五 | 日本69av| 又黄又爽的免费视频 | japan高清日本乱xxxxx | 成人自拍av | av影视天堂 | 91看片黄| 少妇激情网| 超碰在线观看99 | 怨女1988国语版在线观看高清 | 久久综合91 | 午夜视频福利网站 | 国产精品国产三级国产专区51区 | 999视频在线播放 | 亚洲图区综合 | 新91视频在线观看 | 黄色三级在线播放 | www.亚洲| 一级片视频免费看 | 国产精品系列在线播放 | 亚洲免费福利视频 | 最近高清中文在线字幕在线观看 | 69久久精品无码一区二区 | a视频网站 | 黄色网址在线看 | 久久爱99 | 国产精品区一区二 | www.99在线 | 手机福利视频 | 亚洲三级影视 | 99热首页 | 国产精品丝袜黑色高跟鞋的设计特点 | 亚洲一区二区图片 | 一本久道综合色婷婷五月 | 国产伦精品一区二区三区四区 | 成年女人免费视频 | 国产精品美女主播 | 午夜影院免费观看 | 国产91在线看 | 欧美xxxxx精品 | 久久精品国产77777蜜臀 | 国产区一二 | 91在线无精精品入口 | av不卡在线 | 熟妇高潮一区二区高潮 | 一级片在线免费播放 | 欧洲人妻丰满av无码久久不卡 | 精品人妻av一区二区三区 | 四虎在线视频免费观看 | 草逼视频网站 |