Mercurial > hg > nginx
comparison src/http/ngx_http_core_module.c @ 1454:f497ed7682a7
open_file_cache in HTTP
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sat, 01 Sep 2007 12:12:48 +0000 |
parents | 99fb4fdbd53a |
children | 223e92651ca5 |
comparison
equal
deleted
inserted
replaced
1453:f2feed5bffe1 | 1454:f497ed7682a7 |
---|---|
59 static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 59 static char *ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
60 static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, | 60 static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, |
61 void *conf); | 61 void *conf); |
62 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, | 62 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, |
63 void *conf); | 63 void *conf); |
64 static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, | |
65 void *conf); | |
64 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, | 66 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, |
65 void *conf); | 67 void *conf); |
66 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, | 68 static char *ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, |
67 void *conf); | 69 void *conf); |
68 static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, | 70 static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, |
446 ngx_http_core_error_log, | 448 ngx_http_core_error_log, |
447 NGX_HTTP_LOC_CONF_OFFSET, | 449 NGX_HTTP_LOC_CONF_OFFSET, |
448 0, | 450 0, |
449 NULL }, | 451 NULL }, |
450 | 452 |
451 #if (NGX_HTTP_CACHE) | |
452 | |
453 { ngx_string("open_file_cache"), | 453 { ngx_string("open_file_cache"), |
454 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE4, | 454 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12, |
455 ngx_http_set_cache_slot, | 455 ngx_http_core_open_file_cache, |
456 NGX_HTTP_LOC_CONF_OFFSET, | 456 NGX_HTTP_LOC_CONF_OFFSET, |
457 offsetof(ngx_http_core_loc_conf_t, open_files), | 457 offsetof(ngx_http_core_loc_conf_t, open_file_cache), |
458 NULL }, | 458 NULL }, |
459 | 459 |
460 #endif | 460 { ngx_string("open_file_cache_retest"), |
461 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
462 ngx_conf_set_sec_slot, | |
463 NGX_HTTP_LOC_CONF_OFFSET, | |
464 offsetof(ngx_http_core_loc_conf_t, open_file_cache_retest), | |
465 NULL }, | |
466 | |
467 { ngx_string("open_file_cache_errors"), | |
468 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
469 ngx_conf_set_flag_slot, | |
470 NGX_HTTP_LOC_CONF_OFFSET, | |
471 offsetof(ngx_http_core_loc_conf_t, open_file_cache_errors), | |
472 NULL }, | |
461 | 473 |
462 ngx_null_command | 474 ngx_null_command |
463 }; | 475 }; |
464 | 476 |
465 | 477 |
2358 lcf->msie_refresh = NGX_CONF_UNSET; | 2370 lcf->msie_refresh = NGX_CONF_UNSET; |
2359 lcf->log_not_found = NGX_CONF_UNSET; | 2371 lcf->log_not_found = NGX_CONF_UNSET; |
2360 lcf->recursive_error_pages = NGX_CONF_UNSET; | 2372 lcf->recursive_error_pages = NGX_CONF_UNSET; |
2361 lcf->types_hash_max_size = NGX_CONF_UNSET_UINT; | 2373 lcf->types_hash_max_size = NGX_CONF_UNSET_UINT; |
2362 lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT; | 2374 lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT; |
2375 lcf->open_file_cache = NGX_CONF_UNSET_PTR; | |
2376 lcf->open_file_cache_retest = NGX_CONF_UNSET; | |
2377 lcf->open_file_cache_errors = NGX_CONF_UNSET; | |
2363 | 2378 |
2364 return lcf; | 2379 return lcf; |
2365 } | 2380 } |
2366 | 2381 |
2367 | 2382 |
2541 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0); | 2556 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0); |
2542 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1); | 2557 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1); |
2543 ngx_conf_merge_value(conf->recursive_error_pages, | 2558 ngx_conf_merge_value(conf->recursive_error_pages, |
2544 prev->recursive_error_pages, 0); | 2559 prev->recursive_error_pages, 0); |
2545 | 2560 |
2546 if (conf->open_files == NULL) { | 2561 ngx_conf_merge_ptr_value(conf->open_file_cache, |
2547 conf->open_files = prev->open_files; | 2562 prev->open_file_cache, NULL); |
2548 } | 2563 |
2564 ngx_conf_merge_sec_value(conf->open_file_cache_retest, | |
2565 prev->open_file_cache_retest, 60); | |
2566 | |
2567 ngx_conf_merge_sec_value(conf->open_file_cache_errors, | |
2568 prev->open_file_cache_errors, 0); | |
2549 | 2569 |
2550 return NGX_CONF_OK; | 2570 return NGX_CONF_OK; |
2551 } | 2571 } |
2552 | 2572 |
2553 | 2573 |
3160 return NGX_CONF_OK; | 3180 return NGX_CONF_OK; |
3161 } | 3181 } |
3162 | 3182 |
3163 | 3183 |
3164 static char * | 3184 static char * |
3185 ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
3186 { | |
3187 ngx_http_core_loc_conf_t *lcf = conf; | |
3188 | |
3189 time_t inactive; | |
3190 ngx_str_t *value, s; | |
3191 ngx_int_t max; | |
3192 ngx_uint_t i; | |
3193 | |
3194 if (lcf->open_file_cache != NGX_CONF_UNSET_PTR) { | |
3195 return "is duplicate"; | |
3196 } | |
3197 | |
3198 value = cf->args->elts; | |
3199 | |
3200 max = 0; | |
3201 inactive = 60; | |
3202 | |
3203 for (i = 1; i < cf->args->nelts; i++) { | |
3204 | |
3205 if (ngx_strncmp(value[i].data, "max=", 4) == 0) { | |
3206 | |
3207 max = ngx_atoi(value[i].data + 4, value[i].len - 4); | |
3208 if (max == NGX_ERROR) { | |
3209 return NGX_CONF_ERROR; | |
3210 } | |
3211 | |
3212 continue; | |
3213 } | |
3214 | |
3215 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) { | |
3216 | |
3217 s.len = value[i].len - 9; | |
3218 s.data = value[i].data + 9; | |
3219 | |
3220 inactive = ngx_parse_time(&s, 1); | |
3221 if (inactive < 0) { | |
3222 return NGX_CONF_ERROR; | |
3223 } | |
3224 | |
3225 continue; | |
3226 } | |
3227 | |
3228 if (ngx_strcmp(value[i].data, "off") == 0) { | |
3229 | |
3230 lcf->open_file_cache = NULL; | |
3231 | |
3232 continue; | |
3233 } | |
3234 | |
3235 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
3236 "invalid \"open_file_cache\" parameter \"%V\"", | |
3237 &value[i]); | |
3238 return NGX_CONF_ERROR; | |
3239 } | |
3240 | |
3241 if (lcf->open_file_cache == NULL) { | |
3242 return NGX_CONF_OK; | |
3243 } | |
3244 | |
3245 if (max == 0) { | |
3246 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
3247 "\"open_file_cache\" must have \"max\" parameter"); | |
3248 return NGX_CONF_ERROR; | |
3249 } | |
3250 | |
3251 lcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive); | |
3252 if (lcf->open_file_cache) { | |
3253 return NGX_CONF_OK; | |
3254 } | |
3255 | |
3256 return NGX_CONF_ERROR; | |
3257 } | |
3258 | |
3259 | |
3260 static char * | |
3165 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 3261 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
3166 { | 3262 { |
3167 ngx_http_core_loc_conf_t *lcf = conf; | 3263 ngx_http_core_loc_conf_t *lcf = conf; |
3168 | 3264 |
3169 lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args); | 3265 lcf->err_log = ngx_log_create_errlog(cf->cycle, cf->args); |