php / php/php-src

php-fpm access.format: allow environment variables (in addition to fastcgi env vars)

Aperta
#11,131 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@bukka ci sta già lavorando.

Dal 5/5/2023.

Feature SAPI: fpm Status: Needs Triage
Lingua principale
C
Stelle
40.4k
Fork
8.1k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

Description

We're using the patch below to inject environment variables into the php-fpm access log, e.g. for statistics about outgoing requests that were performed using curl. Example usage:

access.format = "{"uid":"%{UNIQUE_ID}E","timestamp":%{%s}t,"requesttime":%{request_time}E,"requestvolume":"%{request_volume}E}"

Could you provide some guidance if this has any change to be accepted, and if so, how I can help in the process?

diff --git a/sapi/fpm/fpm/fpm_log.c b/sapi/fpm/fpm/fpm_log.c
index bb66c0812..518aba4aa 100644
--- a/sapi/fpm/fpm/fpm_log.c
+++ b/sapi/fpm/fpm/fpm_log.c
@@ -247,7 +247,7 @@ int fpm_log_write(char *log_format) /* {{{ */
 
 				case 'e': /* fastcgi env  */
 					if (format[0] == '\0') {
-						zlog(ZLOG_WARNING, "the name of the environment variable must be set between embraces for %%%c", *s);
+						zlog(ZLOG_WARNING, "the name of the environment variable must be set between curly braces for %%%c", *s);
 						return -1;
 					}
 
@@ -258,6 +258,19 @@ int fpm_log_write(char *log_format) /* {{{ */
 					format[0] = '\0';
 					break;
 
+				case 'E': /* env */
+					if (format[0] == '\0') {
+						zlog(ZLOG_WARNING, "the name of the environment variable must be set between curly braces for %%%c", *s);
+						return -1;
+					}
+
+					if (!test) {
+						char *env = getenv(format);
+						len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s", env ? env : "-");
+					}
+					format[0] = '\0';
+					break;
+
 				case 'f': /* script */
 					if (!test) {
 						len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s",  *proc.script_filename ? proc.script_filename : "-");
@@ -526,4 +539,4 @@ static int fpm_access_log_suppress(struct fpm_scoreboard_proc_s *proc)
 	}
 
 	return 0;
-}
\ No newline at end of file
+}

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.