@@ -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 , has_start_time ;
@@ -170,9 +170,17 @@ 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 ("_GET" , sizeof ("_GET" )- 1 , 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
+ has_start_time = 1 ;
180
+
173
181
scoreboard_p = fpm_scoreboard_get ();
174
- if (scoreboard_p -> shared ) {
175
- scoreboard_p = scoreboard_p -> shared ;
182
+ if (scoreboard_p ) {
183
+ scoreboard_p = fpm_scoreboard_copy ( scoreboard_p -> shared ? scoreboard_p -> shared : scoreboard_p , full ) ;
176
184
}
177
185
if (!scoreboard_p ) {
178
186
zlog (ZLOG_ERROR , "status: unable to find or access status shared memory" );
@@ -184,21 +192,9 @@ int fpm_status_handle_request(void) /* {{{ */
184
192
return 1 ;
185
193
}
186
194
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 );
195
+ if (scoreboard_p -> idle < 0 || scoreboard_p -> active < 0 ) {
196
+ fpm_scoreboard_free_copy (scoreboard_p );
197
+ zlog (ZLOG_ERROR , "[pool %s] invalid status values" , scoreboard_p -> pool );
202
198
SG (sapi_headers ).http_response_code = 500 ;
203
199
sapi_add_header_ex (ZEND_STRL ("Content-Type: text/plain" ), 1 , 1 );
204
200
sapi_add_header_ex (ZEND_STRL ("Expires: Thu, 01 Jan 1970 00:00:00 GMT" ), 1 , 1 );
@@ -214,17 +210,10 @@ int fpm_status_handle_request(void) /* {{{ */
214
210
215
211
/* handle HEAD */
216
212
if (SG (request_info ).headers_only ) {
213
+ fpm_scoreboard_free_copy (scoreboard_p );
217
214
return 1 ;
218
215
}
219
216
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
- has_start_time = 1 ;
227
-
228
217
/* HTML */
229
218
if (fpm_php_get_string_from_table (_GET_str , "html" )) {
230
219
sapi_add_header_ex (ZEND_STRL ("Content-Type: text/html" ), 1 , 1 );
@@ -486,37 +475,37 @@ int fpm_status_handle_request(void) /* {{{ */
486
475
487
476
now_epoch = time (NULL );
488
477
if (has_start_time ) {
489
- strftime (time_buffer , sizeof (time_buffer ) - 1 , time_format , localtime (& scoreboard . start_epoch ));
478
+ strftime (time_buffer , sizeof (time_buffer ) - 1 , time_format , localtime (& scoreboard_p -> start_epoch ));
490
479
spprintf (& buffer , 0 , short_syntax ,
491
- scoreboard . pool ,
492
- PM2STR (scoreboard . pm ),
480
+ scoreboard_p -> pool ,
481
+ PM2STR (scoreboard_p -> pm ),
493
482
time_buffer ,
494
- (unsigned long ) (now_epoch - scoreboard . start_epoch ),
495
- scoreboard . requests ,
496
- scoreboard . lq ,
497
- scoreboard . lq_max ,
498
- scoreboard . lq_len ,
499
- scoreboard . idle ,
500
- scoreboard . active ,
501
- scoreboard . idle + scoreboard . active ,
502
- scoreboard . active_max ,
503
- scoreboard . max_children_reached ,
504
- scoreboard . slow_rq );
483
+ (unsigned long ) (now_epoch - scoreboard_p -> start_epoch ),
484
+ scoreboard_p -> requests ,
485
+ scoreboard_p -> lq ,
486
+ scoreboard_p -> lq_max ,
487
+ scoreboard_p -> lq_len ,
488
+ scoreboard_p -> idle ,
489
+ scoreboard_p -> active ,
490
+ scoreboard_p -> idle + scoreboard_p -> active ,
491
+ scoreboard_p -> active_max ,
492
+ scoreboard_p -> max_children_reached ,
493
+ scoreboard_p -> slow_rq );
505
494
} else {
506
495
spprintf (& buffer , 0 , short_syntax ,
507
- scoreboard . pool ,
508
- PM2STR (scoreboard . pm ),
509
- (unsigned long ) (now_epoch - scoreboard . start_epoch ),
510
- scoreboard . requests ,
511
- scoreboard . lq ,
512
- scoreboard . lq_max ,
513
- scoreboard . lq_len ,
514
- scoreboard . idle ,
515
- scoreboard . active ,
516
- scoreboard . idle + scoreboard . active ,
517
- scoreboard . active_max ,
518
- scoreboard . max_children_reached ,
519
- scoreboard . slow_rq );
496
+ scoreboard_p -> pool ,
497
+ PM2STR (scoreboard_p -> pm ),
498
+ (unsigned long ) (now_epoch - scoreboard_p -> start_epoch ),
499
+ scoreboard_p -> requests ,
500
+ scoreboard_p -> lq ,
501
+ scoreboard_p -> lq_max ,
502
+ scoreboard_p -> lq_len ,
503
+ scoreboard_p -> idle ,
504
+ scoreboard_p -> active ,
505
+ scoreboard_p -> idle + scoreboard_p -> active ,
506
+ scoreboard_p -> active_max ,
507
+ scoreboard_p -> max_children_reached ,
508
+ scoreboard_p -> slow_rq );
520
509
}
521
510
522
511
PUTS (buffer );
@@ -547,7 +536,7 @@ int fpm_status_handle_request(void) /* {{{ */
547
536
if (!scoreboard_p -> procs [i ].used ) {
548
537
continue ;
549
538
}
550
- proc = scoreboard_p -> procs [i ];
539
+ proc = & scoreboard_p -> procs [i ];
551
540
552
541
if (first ) {
553
542
first = 0 ;
@@ -559,44 +548,44 @@ int fpm_status_handle_request(void) /* {{{ */
559
548
560
549
query_string = NULL ;
561
550
tmp_query_string = NULL ;
562
- if (proc . query_string [0 ] != '\0' ) {
551
+ if (proc -> query_string [0 ] != '\0' ) {
563
552
if (!encode ) {
564
- query_string = proc . query_string ;
553
+ query_string = proc -> query_string ;
565
554
} else {
566
- 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 );
555
+ 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 );
567
556
query_string = ZSTR_VAL (tmp_query_string );
568
557
}
569
558
}
570
559
571
560
/* prevent NaN */
572
- if (proc . cpu_duration .tv_sec == 0 && proc . cpu_duration .tv_usec == 0 ) {
561
+ if (proc -> cpu_duration .tv_sec == 0 && proc -> cpu_duration .tv_usec == 0 ) {
573
562
cpu = 0. ;
574
563
} else {
575
- 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. ;
564
+ 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. ;
576
565
}
577
566
578
- if (proc . request_stage == FPM_REQUEST_ACCEPTING ) {
579
- duration = proc . duration ;
567
+ if (proc -> request_stage == FPM_REQUEST_ACCEPTING ) {
568
+ duration = proc -> duration ;
580
569
} else {
581
- timersub (& now , & proc . accepted , & duration );
570
+ timersub (& now , & proc -> accepted , & duration );
582
571
}
583
- strftime (time_buffer , sizeof (time_buffer ) - 1 , time_format , localtime (& proc . start_epoch ));
572
+ strftime (time_buffer , sizeof (time_buffer ) - 1 , time_format , localtime (& proc -> start_epoch ));
584
573
spprintf (& buffer , 0 , full_syntax ,
585
- (int ) proc . pid ,
586
- fpm_request_get_stage_name (proc . request_stage ),
574
+ (int ) proc -> pid ,
575
+ fpm_request_get_stage_name (proc -> request_stage ),
587
576
time_buffer ,
588
- (unsigned long ) (now_epoch - proc . start_epoch ),
589
- proc . requests ,
577
+ (unsigned long ) (now_epoch - proc -> start_epoch ),
578
+ proc -> requests ,
590
579
duration .tv_sec * 1000000UL + duration .tv_usec ,
591
- proc . request_method [0 ] != '\0' ? proc . request_method : "-" ,
592
- proc . request_uri [0 ] != '\0' ? proc . request_uri : "-" ,
580
+ proc -> request_method [0 ] != '\0' ? proc -> request_method : "-" ,
581
+ proc -> request_uri [0 ] != '\0' ? proc -> request_uri : "-" ,
593
582
query_string ? "?" : "" ,
594
583
query_string ? query_string : "" ,
595
- proc . content_length ,
596
- proc . auth_user [0 ] != '\0' ? proc . auth_user : "-" ,
597
- proc . script_filename [0 ] != '\0' ? proc . script_filename : "-" ,
598
- proc . request_stage == FPM_REQUEST_ACCEPTING ? cpu : 0. ,
599
- proc . request_stage == FPM_REQUEST_ACCEPTING ? proc . memory : 0 );
584
+ proc -> content_length ,
585
+ proc -> auth_user [0 ] != '\0' ? proc -> auth_user : "-" ,
586
+ proc -> script_filename [0 ] != '\0' ? proc -> script_filename : "-" ,
587
+ proc -> request_stage == FPM_REQUEST_ACCEPTING ? cpu : 0. ,
588
+ proc -> request_stage == FPM_REQUEST_ACCEPTING ? proc -> memory : 0 );
600
589
PUTS (buffer );
601
590
efree (buffer );
602
591
@@ -610,6 +599,7 @@ int fpm_status_handle_request(void) /* {{{ */
610
599
}
611
600
}
612
601
602
+ fpm_scoreboard_free_copy (scoreboard_p );
613
603
return 1 ;
614
604
}
615
605
0 commit comments