当 php 设置为记录到 syslog 时记录 REQUEST_URI 变量
这是php_log_err的源代码。 我想修改它以便能够记录变量 _SERVER["REQUEST_URI"]
/* {{{ php_log_err
*/
PHPAPI void php_log_err(char *log_message TSRMLS_DC)
{
FILE *log_file;
char error_time_str[128];
struct tm tmbuf;
time_t error_time;
/* Try to use the specified logging location. */
if (PG(error_log) != NULL) {
#ifdef HAVE_SYSLOG_H
if (!strcmp(PG(error_log), "syslog")) {
php_syslog(LOG_NOTICE, "%.500s", log_message);
return;
}
#endif
log_file = VCWD_FOPEN(PG(error_log), "ab");
if (log_file != NULL) {
time(&error_time);
strftime(error_time_str, sizeof(error_time_str), "%d-%b-%Y %H:%M:%S", php_localtime_r(&error_time, &tmbuf));
fprintf(log_file, "[%s] ", error_time_str);
fprintf(log_file, "%s", log_message);
fprintf(log_file, "%s", PHP_EOL);
fclose(log_file);
return;
}
}
/* Otherwise fall back to the default logging location, if we have one */
if (sapi_module.log_message) {
sapi_module.log_message(log_message);
}
}
/* }}} */
我已经得到了这个,这应该离解决方案不远,但我无法让它工作:
char key[] = "REQUEST_URI";
int key_size = sizeof(key);
zval **hsv;
zval **var;
if (SUCCESS != zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &hsv)) {
if (SUCCESS != zend_hash_find(Z_ARRVAL_PP(hsv), (char *) key, key_size, (void **) &var)) {
if (!(Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) {
}
}
}
This is the source code of php_log_err. I would like to modify it to be able to log the variable _SERVER["REQUEST_URI"]
/* {{{ php_log_err
*/
PHPAPI void php_log_err(char *log_message TSRMLS_DC)
{
FILE *log_file;
char error_time_str[128];
struct tm tmbuf;
time_t error_time;
/* Try to use the specified logging location. */
if (PG(error_log) != NULL) {
#ifdef HAVE_SYSLOG_H
if (!strcmp(PG(error_log), "syslog")) {
php_syslog(LOG_NOTICE, "%.500s", log_message);
return;
}
#endif
log_file = VCWD_FOPEN(PG(error_log), "ab");
if (log_file != NULL) {
time(&error_time);
strftime(error_time_str, sizeof(error_time_str), "%d-%b-%Y %H:%M:%S", php_localtime_r(&error_time, &tmbuf));
fprintf(log_file, "[%s] ", error_time_str);
fprintf(log_file, "%s", log_message);
fprintf(log_file, "%s", PHP_EOL);
fclose(log_file);
return;
}
}
/* Otherwise fall back to the default logging location, if we have one */
if (sapi_module.log_message) {
sapi_module.log_message(log_message);
}
}
/* }}} */
I've got this which shouldn't be far from the solution but I can't get it to work:
char key[] = "REQUEST_URI";
int key_size = sizeof(key);
zval **hsv;
zval **var;
if (SUCCESS != zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &hsv)) {
if (SUCCESS != zend_hash_find(Z_ARRVAL_PP(hsv), (char *) key, key_size, (void **) &var)) {
if (!(Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) {
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系,我终于找到答案了……
Nevermind, I finally found the answer...