@@ -136,8 +136,8 @@ int fpm_status_export_to_zval(zval *status)
136
136
137
137
int fpm_status_handle_request (void ) /* {{{ */
138
138
{
139
- struct fpm_scoreboard_s scoreboard , * scoreboard_p ;
140
- struct fpm_scoreboard_proc_s proc ;
139
+ struct fpm_scoreboard_s * scoreboard_p ;
140
+ struct fpm_scoreboard_proc_s * proc ;
141
141
char * buffer , * time_format , time_buffer [64 ];
142
142
time_t now_epoch ;
143
143
int full , encode ;
@@ -170,9 +170,16 @@ int fpm_status_handle_request(void) /* {{{ */
170
170
if (fpm_status_uri && !strcmp (fpm_status_uri , SG (request_info ).request_uri )) {
171
171
fpm_request_executing ();
172
172
173
+ /* full status ? */
174
+ _GET_str = zend_string_init (ZEND_STRL ("_GET" ), 0 );
175
+ full = (fpm_php_get_string_from_table (_GET_str , "full" ) != NULL );
176
+ short_syntax = short_post = NULL ;
177
+ full_separator = full_pre = full_syntax = full_post = NULL ;
178
+ encode = 0 ;
179
+
173
180
scoreboard_p = fpm_scoreboard_get ();
174
- if (scoreboard_p -> shared ) {
175
- scoreboard_p = scoreboard_p -> shared ;
181
+ if (scoreboard_p ) {
182
+ scoreboard_p = fpm_scoreboard_copy ( scoreboard_p -> shared ? scoreboard_p -> shared : scoreboard_p , full ) ;
176
183
}
177
184
if (!scoreboard_p ) {
178
185
zlog (ZLOG_ERROR , "status: unable to find or access status shared memory" );
@@ -184,21 +191,9 @@ int fpm_status_handle_request(void) /* {{{ */
184
191
return 1 ;
185
192
}
186
193
187
- if (!fpm_spinlock (& scoreboard_p -> lock , 1 )) {
188
- zlog (ZLOG_NOTICE , "[pool %s] status: scoreboard already in used." , scoreboard_p -> pool );
189
- SG (sapi_headers ).http_response_code = 503 ;
190
- sapi_add_header_ex (ZEND_STRL ("Content-Type: text/plain" ), 1 , 1 );
191
- sapi_add_header_ex (ZEND_STRL ("Expires: Thu, 01 Jan 1970 00:00:00 GMT" ), 1 , 1 );
192
- sapi_add_header_ex (ZEND_STRL ("Cache-Control: no-cache, no-store, must-revalidate, max-age=0" ), 1 , 1 );
193
- PUTS ("Server busy. Please try again later." );
194
- return 1 ;
195
- }
196
- /* copy the scoreboard not to bother other processes */
197
- scoreboard = * scoreboard_p ;
198
- fpm_unlock (scoreboard_p -> lock );
199
-
200
- if (scoreboard .idle < 0 || scoreboard .active < 0 ) {
201
- zlog (ZLOG_ERROR , "[pool %s] invalid status values" , scoreboard .pool );
194
+ if (scoreboard_p -> idle < 0 || scoreboard_p -> active < 0 ) {
195
+ fpm_scoreboard_free_copy (scoreboard_p );
196
+ zlog (ZLOG_ERROR , "[pool %s] invalid status values" , scoreboard_p -> pool );
202
197
SG (sapi_headers ).http_response_code = 500 ;
203
198
sapi_add_header_ex (ZEND_STRL ("Content-Type: text/plain" ), 1 , 1 );
204
199
sapi_add_header_ex (ZEND_STRL ("Expires: Thu, 01 Jan 1970 00:00:00 GMT" ), 1 , 1 );
@@ -214,16 +209,10 @@ int fpm_status_handle_request(void) /* {{{ */
214
209
215
210
/* handle HEAD */
216
211
if (SG (request_info ).headers_only ) {
212
+ fpm_scoreboard_free_copy (scoreboard_p );
217
213
return 1 ;
218
214
}
219
215
220
- /* full status ? */
221
- _GET_str = zend_string_init ("_GET" , sizeof ("_GET" )- 1 , 0 );
222
- full = (fpm_php_get_string_from_table (_GET_str , "full" ) != NULL );
223
- short_syntax = short_post = NULL ;
224
- full_separator = full_pre = full_syntax = full_post = NULL ;
225
- encode = 0 ;
226
-
227
216
/* HTML */
228
217
if (fpm_php_get_string_from_table (_GET_str , "html" )) {
229
218
sapi_add_header_ex (ZEND_STRL ("Content-Type: text/html" ), 1 , 1 );
@@ -429,23 +418,23 @@ int fpm_status_handle_request(void) /* {{{ */
429
418
}
430
419
}
431
420
432
- strftime (time_buffer , sizeof (time_buffer ) - 1 , time_format , localtime (& scoreboard . start_epoch ));
421
+ strftime (time_buffer , sizeof (time_buffer ) - 1 , time_format , localtime (& scoreboard_p -> start_epoch ));
433
422
now_epoch = time (NULL );
434
423
spprintf (& buffer , 0 , short_syntax ,
435
- scoreboard . pool ,
436
- PM2STR (scoreboard . pm ),
424
+ scoreboard_p -> pool ,
425
+ PM2STR (scoreboard_p -> pm ),
437
426
time_buffer ,
438
- (unsigned long ) (now_epoch - scoreboard . start_epoch ),
439
- scoreboard . requests ,
440
- scoreboard . lq ,
441
- scoreboard . lq_max ,
442
- scoreboard . lq_len ,
443
- scoreboard . idle ,
444
- scoreboard . active ,
445
- scoreboard . idle + scoreboard . active ,
446
- scoreboard . active_max ,
447
- scoreboard . max_children_reached ,
448
- scoreboard . slow_rq );
427
+ (unsigned long ) (now_epoch - scoreboard_p -> start_epoch ),
428
+ scoreboard_p -> requests ,
429
+ scoreboard_p -> lq ,
430
+ scoreboard_p -> lq_max ,
431
+ scoreboard_p -> lq_len ,
432
+ scoreboard_p -> idle ,
433
+ scoreboard_p -> active ,
434
+ scoreboard_p -> idle + scoreboard_p -> active ,
435
+ scoreboard_p -> active_max ,
436
+ scoreboard_p -> max_children_reached ,
437
+ scoreboard_p -> slow_rq );
449
438
450
439
PUTS (buffer );
451
440
efree (buffer );
@@ -475,7 +464,7 @@ int fpm_status_handle_request(void) /* {{{ */
475
464
if (!scoreboard_p -> procs [i ].used ) {
476
465
continue ;
477
466
}
478
- proc = scoreboard_p -> procs [i ];
467
+ proc = & scoreboard_p -> procs [i ];
479
468
480
469
if (first ) {
481
470
first = 0 ;
@@ -487,44 +476,44 @@ int fpm_status_handle_request(void) /* {{{ */
487
476
488
477
query_string = NULL ;
489
478
tmp_query_string = NULL ;
490
- if (proc . query_string [0 ] != '\0' ) {
479
+ if (proc -> query_string [0 ] != '\0' ) {
491
480
if (!encode ) {
492
- query_string = proc . query_string ;
481
+ query_string = proc -> query_string ;
493
482
} else {
494
- tmp_query_string = php_escape_html_entities_ex ((const unsigned char * ) proc . query_string , strlen (proc . query_string ), 1 , ENT_HTML_IGNORE_ERRORS & ENT_COMPAT , NULL , /* double_encode */ 1 , /* quiet */ 0 );
483
+ tmp_query_string = php_escape_html_entities_ex ((const unsigned char * ) proc -> query_string , strlen (proc -> query_string ), 1 , ENT_HTML_IGNORE_ERRORS & ENT_COMPAT , NULL , /* double_encode */ 1 , /* quiet */ 0 );
495
484
query_string = ZSTR_VAL (tmp_query_string );
496
485
}
497
486
}
498
487
499
488
/* prevent NaN */
500
- if (proc . cpu_duration .tv_sec == 0 && proc . cpu_duration .tv_usec == 0 ) {
489
+ if (proc -> cpu_duration .tv_sec == 0 && proc -> cpu_duration .tv_usec == 0 ) {
501
490
cpu = 0. ;
502
491
} else {
503
- cpu = (proc . last_request_cpu .tms_utime + proc . last_request_cpu .tms_stime + proc . last_request_cpu .tms_cutime + proc . last_request_cpu .tms_cstime ) / fpm_scoreboard_get_tick () / (proc . cpu_duration .tv_sec + proc . cpu_duration .tv_usec / 1000000. ) * 100. ;
492
+ cpu = (proc -> last_request_cpu .tms_utime + proc -> last_request_cpu .tms_stime + proc -> last_request_cpu .tms_cutime + proc -> last_request_cpu .tms_cstime ) / fpm_scoreboard_get_tick () / (proc -> cpu_duration .tv_sec + proc -> cpu_duration .tv_usec / 1000000. ) * 100. ;
504
493
}
505
494
506
- if (proc . request_stage == FPM_REQUEST_ACCEPTING ) {
507
- duration = proc . duration ;
495
+ if (proc -> request_stage == FPM_REQUEST_ACCEPTING ) {
496
+ duration = proc -> duration ;
508
497
} else {
509
- timersub (& now , & proc . accepted , & duration );
498
+ timersub (& now , & proc -> accepted , & duration );
510
499
}
511
- strftime (time_buffer , sizeof (time_buffer ) - 1 , time_format , localtime (& proc . start_epoch ));
500
+ strftime (time_buffer , sizeof (time_buffer ) - 1 , time_format , localtime (& proc -> start_epoch ));
512
501
spprintf (& buffer , 0 , full_syntax ,
513
- (int ) proc . pid ,
514
- fpm_request_get_stage_name (proc . request_stage ),
502
+ (int ) proc -> pid ,
503
+ fpm_request_get_stage_name (proc -> request_stage ),
515
504
time_buffer ,
516
- (unsigned long ) (now_epoch - proc . start_epoch ),
517
- proc . requests ,
505
+ (unsigned long ) (now_epoch - proc -> start_epoch ),
506
+ proc -> requests ,
518
507
duration .tv_sec * 1000000UL + duration .tv_usec ,
519
- proc . request_method [0 ] != '\0' ? proc . request_method : "-" ,
520
- proc . request_uri [0 ] != '\0' ? proc . request_uri : "-" ,
508
+ proc -> request_method [0 ] != '\0' ? proc -> request_method : "-" ,
509
+ proc -> request_uri [0 ] != '\0' ? proc -> request_uri : "-" ,
521
510
query_string ? "?" : "" ,
522
511
query_string ? query_string : "" ,
523
- proc . content_length ,
524
- proc . auth_user [0 ] != '\0' ? proc . auth_user : "-" ,
525
- proc . script_filename [0 ] != '\0' ? proc . script_filename : "-" ,
526
- proc . request_stage == FPM_REQUEST_ACCEPTING ? cpu : 0. ,
527
- proc . request_stage == FPM_REQUEST_ACCEPTING ? proc . memory : 0 );
512
+ proc -> content_length ,
513
+ proc -> auth_user [0 ] != '\0' ? proc -> auth_user : "-" ,
514
+ proc -> script_filename [0 ] != '\0' ? proc -> script_filename : "-" ,
515
+ proc -> request_stage == FPM_REQUEST_ACCEPTING ? cpu : 0. ,
516
+ proc -> request_stage == FPM_REQUEST_ACCEPTING ? proc -> memory : 0 );
528
517
PUTS (buffer );
529
518
efree (buffer );
530
519
@@ -538,6 +527,7 @@ int fpm_status_handle_request(void) /* {{{ */
538
527
}
539
528
}
540
529
530
+ fpm_scoreboard_free_copy (scoreboard_p );
541
531
return 1 ;
542
532
}
543
533
0 commit comments