49#ifdef HAVE_SYS_TYPES_H
50# include <sys/types.h>
70# include <unixlib/local.h>
71int __riscosify_control = __RISCOSIFY_STRICT_UNIX_SPECS;
84#include <php_config.h>
96static void (*php_php_import_environment_variables)(
zval *array_ptr);
103static int parent = 1;
105static int request_body_fd;
106static int fpm_is_running = 0;
108static char *sapi_cgibin_getenv(
const char *
name,
size_t name_len);
111#define PHP_MODE_STANDARD 1
112#define PHP_MODE_HIGHLIGHT 2
113#define PHP_MODE_INDENT 3
114#define PHP_MODE_LINT 4
115#define PHP_MODE_STRIP 5
117static char *php_optarg =
NULL;
118static int php_optind = 1;
124 {
'e', 0,
"profile-info"},
128 {
'n', 0,
"no-php-ini"},
131 {
'y', 1,
"fpm-config"},
135 {
'R', 0,
"allow-to-run-as-root"},
136 {
'D', 0,
"daemonize"},
137 {
'F', 0,
"nodaemonize"},
138 {
'O', 0,
"force-stderr"},
170static void user_config_cache_entry_dtor(
zval *el)
180static int php_cgi_globals_id;
181#define CGIG(v) ZEND_TSRMG(php_cgi_globals_id, php_cgi_globals_struct *, v)
184#define CGIG(v) (php_cgi_globals.v)
194static void print_modules(
void)
201 zend_hash_sort(&sorted_registry, module_name_cmp, 0);
223static void print_extensions(
void)
236#define STDOUT_FILENO 1
239static inline size_t sapi_cgibin_single_write(
const char *str, uint32_t str_length)
244 if (fpm_is_running) {
254#ifdef PHP_WRITE_STDOUT
261 return fwrite(str, 1,
MIN(str_length, 16384), stdout);
266static size_t sapi_cgibin_ub_write(
const char *str,
size_t str_length)
268 const char *
ptr = str;
269 uint32_t remaining = str_length;
272 while (remaining > 0) {
273 ret = sapi_cgibin_single_write(
ptr, remaining);
276 return str_length - remaining;
286static void sapi_cgibin_flush(
void *server_context)
289 if (fpm_is_running) {
291 if (!parent && request) {
301 if (
fflush(stdout) == EOF) {
307#define SAPI_CGI_MAX_HEADER_LENGTH 1024
314 bool ignore_status = 0;
315 int response_status =
SG(sapi_headers).http_response_code;
317 if (
SG(request_info).no_headers == 1) {
326 if (
CGIG(rfc2616_headers) &&
SG(sapi_headers).http_status_line) {
329 if ((
s =
strchr(
SG(sapi_headers).http_status_line,
' '))) {
330 response_status = atoi((
s + 1));
340 if (
SG(sapi_headers).http_status_line &&
341 (
s =
strchr(
SG(sapi_headers).http_status_line,
' ')) != 0 &&
342 (
s -
SG(sapi_headers).http_status_line) >= 5 &&
343 strncasecmp(
SG(sapi_headers).http_status_line,
"HTTP/", 5) == 0
346 response_status = atoi((
s + 1));
361 while (
err->code != 0) {
390 if (!ignore_status) {
395 }
else if (response_status == 304 && h->
header_len >
sizeof(
"Content-Type:") - 1 &&
414# define STDIN_FILENO 0
417#ifndef HAVE_ATTRIBUTE_WEAK
418static void fpm_fcgi_log(
int type,
const char *fmt, ...)
420void fcgi_log(
int type,
const char *fmt, ...)
430static size_t sapi_cgi_read_post(
char *
buffer,
size_t count_bytes)
432 uint32_t read_bytes = 0;
434 size_t remaining =
SG(request_info).content_length -
SG(read_post_bytes);
436 if (remaining < count_bytes) {
437 count_bytes = remaining;
439 while (read_bytes < count_bytes) {
441 if (request_body_fd == -1) {
442 char *request_body_filename =
FCGI_GETENV(request,
"REQUEST_BODY_FILE");
444 if (request_body_filename && *request_body_filename) {
445 request_body_fd = open(request_body_filename, O_RDONLY);
447 if (0 > request_body_fd) {
449 request_body_filename, strerror(
errno),
errno);
456 if (request_body_fd < 0) {
457 tmp_read_bytes =
fcgi_read(request,
buffer + read_bytes, count_bytes - read_bytes);
459 tmp_read_bytes = read(request_body_fd,
buffer + read_bytes, count_bytes - read_bytes);
461 if (tmp_read_bytes <= 0) {
464 read_bytes += tmp_read_bytes;
470static char *sapi_cgibin_getenv(
const char *
name,
size_t name_len)
473 if (fpm_is_running) {
484static char *_sapi_cgibin_putenv(
char *
name,
char *
value)
499static char *sapi_cgi_read_cookies(
void)
507static void cgi_php_load_env_var(
const char *var,
unsigned int var_len,
char *
val,
unsigned int val_len,
void *
arg)
519static void cgi_php_load_env_var_unfilterd(
const char *var,
unsigned int var_len,
char *
val,
unsigned int val_len,
void *
arg)
525static void cgi_php_load_environment_variables(
zval *array_ptr)
527 php_php_import_environment_variables(array_ptr);
530 fcgi_loadenv(request, cgi_php_load_env_var_unfilterd, array_ptr);
533static void cgi_php_import_environment_variables(
zval *array_ptr)
554 php_php_import_environment_variables(array_ptr);
560static void sapi_cgi_register_variables(
zval *track_vars_array)
570 if (
CGIG(fix_pathinfo)) {
571 char *script_name =
SG(request_info).request_uri;
572 unsigned int script_name_len = script_name ?
strlen(script_name) : 0;
573 char *path_info = sapi_cgibin_getenv(
"PATH_INFO",
sizeof(
"PATH_INFO") - 1);
574 unsigned int path_info_len = path_info ?
strlen(path_info) : 0;
576 php_self_len = script_name_len + path_info_len;
577 php_self =
emalloc(php_self_len + 1);
581 memcpy(php_self, script_name, script_name_len + 1);
584 memcpy(php_self + script_name_len, path_info, path_info_len + 1);
593 php_self =
SG(request_info).request_uri ?
SG(request_info).request_uri :
"";
594 php_self_len =
strlen(php_self);
606static void sapi_cgi_log_fastcgi(
int level,
char *message,
size_t len)
616 if (
CGIG(fcgi_logging) && request && message &&
len > 0) {
617 if (
CGIG(fcgi_logging_request_started)) {
620 CGIG(fcgi_logging_request_started) =
true;
630static void sapi_cgi_log_message(
const char *message,
int syslog_type_int)
637static void php_cgi_ini_activate_user_config(
char *path,
int path_len,
const char *doc_root,
int doc_root_len)
649 zend_hash_str_update_ptr(&
CGIG(user_config_cache), path, path_len, entry);
653 if (request_time > entry->
expires) {
664 if (real_path ==
NULL) {
667 real_path_len =
strlen(real_path);
669 path_len = real_path_len;
672 if (path_len > doc_root_len) {
673 s1 = (
char *) doc_root;
675 s_len = doc_root_len;
678 s2 = (
char *) doc_root;
686 if (
strncmp(s1, s2, s_len) == 0) {
687 ptr = s2 + doc_root_len;
698 entry->
expires = request_time +
PG(user_ini_cache_ttl);
706static int sapi_cgi_activate(
void)
709 char *path, *doc_root, *server_name;
710 uint32_t path_len, doc_root_len, server_name_len;
713 if (!
SG(request_info).path_translated) {
722 server_name_len =
strlen(server_name);
723 server_name =
estrndup(server_name, server_name_len);
731 (
PG(user_ini_filename) && *
PG(user_ini_filename))
734 path_len =
strlen(
SG(request_info).path_translated);
737 if (!
IS_SLASH(
SG(request_info).path_translated[path_len])) {
739 memcpy(path,
SG(request_info).path_translated, path_len + 1);
743 path =
estrndup(
SG(request_info).path_translated, path_len);
752 if (
PG(user_ini_filename) && *
PG(user_ini_filename)) {
756 doc_root_len =
strlen(doc_root);
757 if (doc_root_len > 0 &&
IS_SLASH(doc_root[doc_root_len - 1])) {
761 php_cgi_ini_activate_user_config(path, path_len, doc_root, doc_root_len);
772static int sapi_cgi_deactivate(
void)
778 if (
SG(sapi_started)) {
804 sapi_cgibin_ub_write,
812 sapi_cgi_send_headers,
816 sapi_cgi_read_cookies,
818 sapi_cgi_register_variables,
819 sapi_cgi_log_message,
828static void php_cgi_usage(
char *argv0)
839 php_printf(
"Usage: %s [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p <prefix>] [-g <pid>] [-c <file>] [-d foo[=bar]] [-y <file>] [-D] [-F [-O]]\n"
840 " -c <path>|<file> Look for php.ini file in this directory\n"
841 " -n No php.ini file will be used\n"
842 " -d foo[=bar] Define INI entry foo with value 'bar'\n"
843 " -e Generate extended information for debugger/profiler\n"
845 " -i PHP information\n"
846 " -m Show compiled in modules\n"
847 " -v Version number\n"
848 " -p, --prefix <dir>\n"
849 " Specify alternative prefix path to FastCGI process manager (default: %s).\n"
850 " -g, --pid <file>\n"
851 " Specify the PID file location.\n"
852 " -y, --fpm-config <file>\n"
853 " Specify alternative path to FastCGI process manager config file.\n"
854 " -t, --test Test FPM configuration and exit\n"
855 " -D, --daemonize force to run in background, and ignore daemonize option from config file\n"
856 " -F, --nodaemonize\n"
857 " force to stay in foreground, and ignore daemonize option from config file\n"
858 " -O, --force-stderr\n"
859 " force output to stderr in nodaemonize even if stderr is not a TTY\n"
860 " -R, --allow-to-run-as-root\n"
861 " Allow pool to run as root (disabled by default)\n",
871static int is_valid_path(
const char *path)
967static void init_request_info(
void)
970 char *env_script_filename =
FCGI_GETENV(request,
"SCRIPT_FILENAME");
971 char *env_path_translated =
FCGI_GETENV(request,
"PATH_TRANSLATED");
972 char *script_path_translated = env_script_filename;
974 int apache_was_here = 0;
979 if (!script_path_translated && env_path_translated) {
980 script_path_translated = env_path_translated;
984 SG(request_info).path_translated =
NULL;
985 SG(request_info).request_method =
FCGI_GETENV(request,
"REQUEST_METHOD");
986 SG(request_info).proto_num = 1000;
987 SG(request_info).query_string =
NULL;
988 SG(request_info).request_uri =
NULL;
989 SG(request_info).content_type =
NULL;
990 SG(request_info).content_length = 0;
991 SG(sapi_headers).http_response_code = 200;
995 if (script_path_translated) {
997 char *content_length =
FCGI_GETENV(request,
"CONTENT_LENGTH");
998 char *content_type =
FCGI_GETENV(request,
"CONTENT_TYPE");
999 char *env_path_info =
FCGI_GETENV(request,
"PATH_INFO");
1000 char *env_script_name =
FCGI_GETENV(request,
"SCRIPT_NAME");
1003 char *env_server_software =
FCGI_GETENV(request,
"SERVER_SOFTWARE");
1004 if (env_server_software &&
1007 strncmp(env_server_software,
"Microsoft-IIS",
sizeof(
"Microsoft-IIS") - 1) == 0 &&
1008 strncmp(env_path_info, env_script_name,
strlen(env_script_name)) == 0
1010 env_path_info =
FCGI_PUTENV(request,
"ORIG_PATH_INFO", env_path_info);
1011 env_path_info +=
strlen(env_script_name);
1012 if (*env_path_info == 0) {
1013 env_path_info =
NULL;
1015 env_path_info =
FCGI_PUTENV(request,
"PATH_INFO", env_path_info);
1018#define APACHE_PROXY_FCGI_PREFIX "proxy:fcgi://"
1019#define APACHE_PROXY_BALANCER_PREFIX "proxy:balancer://"
1029 if (env_script_filename &&
1033 while (*
p !=
'\0' && *
p !=
'/') {
1041 apache_was_here = 1;
1044 p =
strchr(env_script_filename,
'?');
1050 if (env_script_filename &&
1054 while (*
p !=
'\0' && *
p !=
'/') {
1062 apache_was_here = 1;
1065 p =
strchr(env_script_filename,
'?');
1071 if (
CGIG(fix_pathinfo)) {
1073 char *real_path =
NULL;
1074 char *env_redirect_url =
FCGI_GETENV(request,
"REDIRECT_URL");
1075 char *env_document_root =
FCGI_GETENV(request,
"DOCUMENT_ROOT");
1076 char *orig_path_translated = env_path_translated;
1077 char *orig_path_info = env_path_info;
1078 char *orig_script_name = env_script_name;
1079 char *orig_script_filename = env_script_filename;
1080 int script_path_translated_len;
1082 if (!env_document_root &&
PG(doc_root)) {
1083 env_document_root =
FCGI_PUTENV(request,
"DOCUMENT_ROOT",
PG(doc_root));
1086 if (!apache_was_here && env_path_translated !=
NULL && env_redirect_url !=
NULL &&
1087 env_path_translated != script_path_translated &&
1088 strcmp(env_path_translated, script_path_translated) != 0) {
1097 script_path_translated = env_path_translated;
1099 env_script_name = env_redirect_url;
1104 __riscosify_control |= __RISCOSIFY_DONT_CHECK_DIR;
1105 script_path_translated = __unixify(script_path_translated, 0,
NULL, 1, 0);
1113 if (script_path_translated &&
1114 (script_path_translated_len =
strlen(script_path_translated)) > 0 &&
1115 (script_path_translated[script_path_translated_len-1] ==
'/' ||
1118 char *pt =
estrndup(script_path_translated, script_path_translated_len);
1119 int len = script_path_translated_len;
1142 int slen =
len - ptlen;
1143 int pilen = env_path_info ?
strlen(env_path_info) : 0;
1146 if (apache_was_here) {
1148 path_info = script_path_translated + ptlen;
1149 tflag = (slen != 0 && (!orig_path_info ||
strcmp(orig_path_info, path_info) != 0));
1151 path_info = (env_path_info && pilen > slen) ? env_path_info + pilen - slen :
NULL;
1152 tflag = path_info && (orig_path_info != path_info);
1156 char *decoded_path_info =
NULL;
1157 if (orig_path_info) {
1160 FCGI_PUTENV(request,
"ORIG_PATH_INFO", orig_path_info);
1163 if (!orig_script_name ||
1164 strcmp(orig_script_name, env_path_info) != 0) {
1165 if (orig_script_name) {
1166 FCGI_PUTENV(request,
"ORIG_SCRIPT_NAME", orig_script_name);
1168 SG(request_info).request_uri =
FCGI_PUTENV(request,
"SCRIPT_NAME", env_path_info);
1170 SG(request_info).request_uri = orig_script_name;
1173 }
else if (apache_was_here && env_script_name) {
1178 size_t decoded_path_info_len = 0;
1179 if (
strchr(path_info,
'%')) {
1180 decoded_path_info =
estrdup(path_info);
1183 size_t snlen =
strlen(env_script_name);
1184 size_t env_script_file_info_start = 0;
1188 !
strcmp(env_script_name + (env_script_file_info_start = snlen - slen), path_info)
1191 decoded_path_info &&
1192 snlen > decoded_path_info_len &&
1193 !
strcmp(env_script_name + (env_script_file_info_start = snlen - decoded_path_info_len), decoded_path_info)
1196 FCGI_PUTENV(request,
"ORIG_SCRIPT_NAME", orig_script_name);
1197 env_script_name[env_script_file_info_start] = 0;
1198 SG(request_info).request_uri =
FCGI_PUTENV(request,
"SCRIPT_NAME", env_script_name);
1201 if (decoded_path_info) {
1202 env_path_info =
FCGI_PUTENV(request,
"PATH_INFO", decoded_path_info);
1203 efree(decoded_path_info);
1205 env_path_info =
FCGI_PUTENV(request,
"PATH_INFO", path_info);
1208 if (!orig_script_filename ||
1209 strcmp(orig_script_filename, pt) != 0) {
1210 if (orig_script_filename) {
1211 FCGI_PUTENV(request,
"ORIG_SCRIPT_FILENAME", orig_script_filename);
1213 script_path_translated =
FCGI_PUTENV(request,
"SCRIPT_FILENAME", pt);
1219 if (env_document_root) {
1220 int l =
strlen(env_document_root);
1221 int path_translated_len = 0;
1222 char *path_translated =
NULL;
1224 if (l && env_document_root[l - 1] ==
'/') {
1234 path_translated_len = l + (env_path_info ?
strlen(env_path_info) : 0);
1235 path_translated = (
char *)
emalloc(path_translated_len + 1);
1236 memcpy(path_translated, env_document_root, l);
1237 if (env_path_info) {
1238 memcpy(path_translated + l, env_path_info, (path_translated_len - l));
1240 path_translated[path_translated_len] =
'\0';
1241 if (orig_path_translated) {
1242 FCGI_PUTENV(request,
"ORIG_PATH_TRANSLATED", orig_path_translated);
1244 env_path_translated =
FCGI_PUTENV(request,
"PATH_TRANSLATED", path_translated);
1245 efree(path_translated);
1246 }
else if ( env_script_name &&
1247 strstr(pt, env_script_name)
1251 int path_translated_len = ptlen + (env_path_info ?
strlen(env_path_info) : 0);
1252 char *path_translated =
NULL;
1254 path_translated = (
char *)
emalloc(path_translated_len + 1);
1255 memcpy(path_translated, pt, ptlen);
1256 if (env_path_info) {
1257 memcpy(path_translated + ptlen, env_path_info, path_translated_len - ptlen);
1259 path_translated[path_translated_len] =
'\0';
1260 if (orig_path_translated) {
1261 FCGI_PUTENV(request,
"ORIG_PATH_TRANSLATED", orig_path_translated);
1263 env_path_translated =
FCGI_PUTENV(request,
"PATH_TRANSLATED", path_translated);
1264 efree(path_translated);
1278 if (orig_script_filename) {
1279 FCGI_PUTENV(request,
"ORIG_SCRIPT_FILENAME", orig_script_filename);
1281 script_path_translated =
FCGI_PUTENV(request,
"SCRIPT_FILENAME",
NULL);
1282 SG(sapi_headers).http_response_code = 404;
1284 if (!
SG(request_info).request_uri) {
1285 if (!orig_script_name ||
1286 strcmp(orig_script_name, env_script_name) != 0) {
1287 if (orig_script_name) {
1288 FCGI_PUTENV(request,
"ORIG_SCRIPT_NAME", orig_script_name);
1290 SG(request_info).request_uri =
FCGI_PUTENV(request,
"SCRIPT_NAME", env_script_name);
1292 SG(request_info).request_uri = orig_script_name;
1300 if (!orig_script_filename ||
1301 (script_path_translated != orig_script_filename &&
1302 strcmp(script_path_translated, orig_script_filename) != 0)) {
1303 if (orig_script_filename) {
1304 FCGI_PUTENV(request,
"ORIG_SCRIPT_FILENAME", orig_script_filename);
1306 script_path_translated =
FCGI_PUTENV(request,
"SCRIPT_FILENAME", script_path_translated);
1308 if (!apache_was_here && env_redirect_url) {
1311 if (orig_path_info) {
1312 FCGI_PUTENV(request,
"ORIG_PATH_INFO", orig_path_info);
1315 if (orig_path_translated) {
1316 FCGI_PUTENV(request,
"ORIG_PATH_TRANSLATED", orig_path_translated);
1320 if (env_script_name != orig_script_name) {
1321 if (orig_script_name) {
1322 FCGI_PUTENV(request,
"ORIG_SCRIPT_NAME", orig_script_name);
1324 SG(request_info).request_uri =
FCGI_PUTENV(request,
"SCRIPT_NAME", env_script_name);
1326 SG(request_info).request_uri = env_script_name;
1332 if (env_path_info) {
1333 SG(request_info).request_uri = env_path_info;
1335 SG(request_info).request_uri = env_script_name;
1337 if (!
CGIG(discard_path) && env_path_translated) {
1338 script_path_translated = env_path_translated;
1342 if (is_valid_path(script_path_translated)) {
1343 SG(request_info).path_translated =
estrdup(script_path_translated);
1347 SG(request_info).query_string =
FCGI_GETENV(request,
"QUERY_STRING");
1348 SG(request_info).content_type = (content_type ? content_type :
"" );
1349 SG(request_info).content_length = (content_length ? atol(content_length) : 0);
1352 auth =
FCGI_GETENV(request,
"HTTP_AUTHORIZATION");
1396 zlog(
ZLOG_ERROR,
"Passing INI directive through FastCGI: only classic entries are allowed");
1403 zlog(
ZLOG_ERROR,
"Passing INI directive through FastCGI: empty key");
1412 zlog(
ZLOG_ERROR,
"Passing INI directive through FastCGI: empty value for key '%s'",
key);
1420 zlog(
ZLOG_ERROR,
"Passing INI directive through FastCGI: unable to set '%s'",
key);
1440 php_cgi_globals->rfc2616_headers = 0;
1441 php_cgi_globals->nph = 0;
1442 php_cgi_globals->force_redirect = 1;
1443 php_cgi_globals->redirect_status_env =
NULL;
1444 php_cgi_globals->fix_pathinfo = 1;
1445 php_cgi_globals->discard_path = 0;
1446 php_cgi_globals->fcgi_logging = 1;
1447 php_cgi_globals->fcgi_logging_request_started =
false;
1448 zend_hash_init(&php_cgi_globals->user_config_cache, 0,
NULL, user_config_cache_entry_dtor, 1);
1449 php_cgi_globals->error_header =
NULL;
1450 php_cgi_globals->fpm_config =
NULL;
1460 php_cgi_globals_ctor(&php_cgi_globals);
1554 int cgi = 0, c, use_extended_info = 0;
1558 int orig_optind = php_optind;
1559 char *orig_optarg = php_optarg;
1563 int max_requests = 0;
1567 char *fpm_config =
NULL;
1568 char *fpm_prefix =
NULL;
1569 char *fpm_pid =
NULL;
1571 int force_daemon = -1;
1572 int force_stderr = 0;
1573 int php_information = 0;
1574 int php_allow_to_run_as_root = 0;
1579#if defined(SIGPIPE) && defined(SIG_IGN)
1600 cgi_sapi_module.php_ini_path_override =
NULL;
1601 cgi_sapi_module.php_ini_ignore_cwd = 1;
1603#ifndef HAVE_ATTRIBUTE_WEAK
1609 php_ini_builder_init(&ini_builder);
1611 while ((c =
php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
1614 if (cgi_sapi_module.php_ini_path_override) {
1615 free(cgi_sapi_module.php_ini_path_override);
1617 cgi_sapi_module.php_ini_path_override = strdup(php_optarg);
1621 cgi_sapi_module.php_ini_ignore = 1;
1628 cgi_sapi_module.ini_entries = php_ini_builder_finish(&ini_builder);
1632 fpm_config = php_optarg;
1636 fpm_prefix = php_optarg;
1640 fpm_pid = php_optarg;
1644 use_extended_info = 1;
1652 cgi_sapi_module.startup(&cgi_sapi_module);
1667 php_information = 1;
1671 php_allow_to_run_as_root = 1;
1690 cgi_sapi_module.startup(&cgi_sapi_module);
1693 php_cgi_usage(argv[0]);
1701 cgi_sapi_module.startup(&cgi_sapi_module);
1703 SG(server_context) =
NULL;
1708 SG(request_info).no_headers = 1;
1718 cgi_sapi_module.ini_entries = php_ini_builder_finish(&ini_builder);
1720 if (php_information) {
1721 cgi_sapi_module.phpinfo_as_text = 1;
1722 cgi_sapi_module.startup(&cgi_sapi_module);
1724 SG(server_context) =
NULL;
1729 SG(request_info).no_headers = 1;
1738 if (argc != php_optind) {
1739 cgi_sapi_module.startup(&cgi_sapi_module);
1742 php_cgi_usage(argv[0]);
1750 php_optind = orig_optind;
1751 php_optarg = orig_optarg;
1754 SG(request_info).path_translated =
NULL;
1757 cgi_sapi_module.additional_functions =
NULL;
1758 cgi_sapi_module.executable_location = argv[0];
1761 if (cgi_sapi_module.startup(&cgi_sapi_module) ==
FAILURE) {
1768 if (use_extended_info) {
1773 if (cgi &&
CGIG(force_redirect)) {
1780 if (!
getenv(
"REDIRECT_STATUS") &&
1781 !
getenv (
"HTTP_REDIRECT_STATUS") &&
1784 (!
CGIG(redirect_status_env) || !
getenv(
CGIG(redirect_status_env)))
1787 SG(sapi_headers).http_response_code = 400;
1788 PUTS(
"<b>Security Alert!</b> The PHP CGI cannot be accessed directly.\n\n\
1789<p>This PHP CGI binary was compiled with force-cgi-redirect enabled. This\n\
1790means that a page will only be served up if the REDIRECT_STATUS CGI variable is\n\
1791set, e.g. via an Apache Action directive.</p>\n\
1792<p>For more information as to <i>why</i> this behaviour exists, see the <a href=\"http://php.net/security.cgi-bin\">\
1793manual page for CGI security</a>.</p>\n\
1794<p>For more information about changing this behaviour or re-enabling this webserver,\n\
1795consult the installation file that came with this distribution, or visit \n\
1796<a href=\"http://php.net/install.windows\">the manual page</a>.</p>\n");
1799#if defined(ZTS) && !PHP_DEBUG
1813 old_rc_debug = zend_rc_debug;
1817 enum fpm_init_return_status ret =
fpm_init(argc, argv, fpm_config ? fpm_config :
CGIG(fpm_config), fpm_prefix, fpm_pid, test_conf, php_allow_to_run_as_root, force_daemon, force_stderr);
1820 zend_rc_debug = old_rc_debug;
1845 fcgi_fd =
fpm_run(&max_requests);
1857 request = fpm_init_request(fcgi_fd);
1861 char *primary_script =
NULL;
1862 request_body_fd = -1;
1863 SG(server_context) = (
void *) request;
1864 CGIG(fcgi_logging_request_started) =
false;
1865 init_request_info();
1873 SG(server_context) =
NULL;
1881 goto fastcgi_request_done;
1885 goto fastcgi_request_done;
1892 SG(sapi_headers).http_response_code = 404;
1893 PUTS(
"File not found.\n");
1896 goto fastcgi_request_done;
1900 SG(sapi_headers).http_response_code = 403;
1901 PUTS(
"Access denied.\n");
1902 goto fastcgi_request_done;
1909 primary_script =
estrdup(
SG(request_info).path_translated);
1914 zlog(
ZLOG_ERROR,
"Unable to open primary script: %s (%s)", primary_script, strerror(
errno));
1915 if (
errno == EACCES) {
1916 SG(sapi_headers).http_response_code = 403;
1917 PUTS(
"Access denied.\n");
1919 SG(sapi_headers).http_response_code = 404;
1920 PUTS(
"No input file specified.\n");
1930 EG(exit_status) = 0;
1942fastcgi_request_done:
1944 efree(primary_script);
1948 close(request_body_fd);
1950 request_body_fd = -2;
1965 efree(
SG(request_info).path_translated);
1966 SG(request_info).path_translated =
NULL;
1973 if (
UNEXPECTED(max_requests && (requests == max_requests))) {
1983 if (cgi_sapi_module.php_ini_path_override) {
1984 free(cgi_sapi_module.php_ini_path_override);
1986 php_ini_builder_deinit(&ini_builder);
1993 SG(server_context) =
NULL;
SAPI_API double sapi_get_request_time(void)
SAPI_API sapi_module_struct sapi_module
SAPI_API int sapi_send_headers(void)
SAPI_API void sapi_add_request_header(const char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg)
SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg)
SAPI_API void sapi_startup(sapi_module_struct *sf)
SAPI_API void sapi_shutdown(void)
#define SAPI_HEADER_SENT_SUCCESSFULLY
#define STANDARD_SAPI_MODULE_PROPERTIES
struct _sapi_module_struct sapi_module_struct
file_private const char ext[]
getenv(?string $name=null, bool $local_only=false)
http_response_code(int $response_code=0)
strrchr(string $haystack, string $needle, bool $before_needle=false)
fwrite($stream, string $data, ?int $length=null)
strstr(string $haystack, string $needle, bool $before_needle=false)
strchr(string $haystack, string $needle, bool $before_needle=false)
headers_sent(&$filename=null, &$line=null)
struct _php_cgi_globals_struct php_cgi_globals_struct
struct _user_config_cache_entry user_config_cache_entry
#define SAPI_CGI_MAX_HEADER_LENGTH
void fcgi_request_set_keep(fcgi_request *req, int new_value)
int fcgi_accept_request(fcgi_request *req)
void fcgi_destroy_request(fcgi_request *req)
int fcgi_read(fcgi_request *req, char *str, int len)
int fcgi_flush(fcgi_request *req, int end)
fcgi_request * fcgi_init_request(int listen_socket, void(*on_accept)(void), void(*on_read)(void), void(*on_close)(void))
void fcgi_loadenv(fcgi_request *req, fcgi_apply_func func, zval *array)
int fcgi_end(fcgi_request *req)
int fcgi_is_closed(fcgi_request *req)
int fcgi_write(fcgi_request *req, fcgi_request_type type, const char *str, int len)
char * fcgi_getenv(fcgi_request *req, const char *var, int var_len)
int fcgi_finish_request(fcgi_request *req, int force_close)
char * fcgi_putenv(fcgi_request *req, char *var, int var_len, char *val)
void fcgi_close(fcgi_request *req, int force, int destroy)
#define FCGI_PUTENV(request, name, value)
void void fcgi_set_logger(fcgi_logger lg)
#define FCGI_GETENV(request, name)
struct _fcgi_request fcgi_request
zend_ffi_ctype_name_buf buf
PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle)
int fpm_run(int *max_requests)
struct fpm_globals_s fpm_globals
enum fpm_init_return_status fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon, int force_stderr)
#define FPM_EXIT_SOFTWARE
int fpm_log_write(char *log_format)
#define APACHE_PROXY_FCGI_PREFIX
#define APACHE_PROXY_BALANCER_PREFIX
int fpm_php_limit_extensions(char *path)
int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode)
void fpm_request_accepting(void)
void fpm_request_finished(void)
void fpm_request_info(void)
void fpm_request_reading_headers(void)
void fpm_request_end(void)
void fpm_request_executing(void)
int fpm_signals_init_mask(void)
int fpm_signals_block(void)
int fpm_status_handle_request(void)
int fpm_status_export_to_zval(zval *status)
int fpm_stdio_flush_child(void)
PHPAPI int php_getopt(int argc, char *const *argv, const opt_struct opts[], char **optarg, int *optind, int show_err, int arg_start)
PHPAPI bool php_header(void)
struct _http_response_status_code_pair http_response_status_code_pair
PHPAPI ZEND_COLD void php_print_info(int flag)
PHPAPI size_t php_printf(const char *format,...)
void php_request_shutdown(void *dummy)
zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_module)
PHPAPI void php_handle_aborted_connection(void)
PHPAPI bool php_execute_script(zend_file_handle *primary_file)
void php_module_shutdown(void)
PHPAPI void php_print_version(sapi_module_struct *sapi_module)
zend_result php_request_startup(void)
PHPAPI int php_handle_auth_data(const char *auth)
int php_module_shutdown_wrapper(sapi_module_struct *sapi_globals)
PHPAPI void php_output_end_all(void)
PHPAPI int php_output_activate(void)
PHPAPI void php_output_deactivate(void)
php_info_print_table_start()
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled")
php_info_print_table_end()
#define PHP_MSHUTDOWN_FUNCTION
#define PHP_MINIT_FUNCTION
#define PHP_MINFO_FUNCTION
unsigned const char * pos
#define PHP_GETOPT_INVALID_ARG
struct _opt_struct opt_struct
#define TRACK_VARS_SERVER
PHPAPI void config_zval_dtor(zval *zvalue)
PHPAPI int php_parse_user_ini_file(const char *dirname, const char *ini_filename, HashTable *target_hash)
PHPAPI int php_ini_has_per_host_config(void)
PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int stage)
PHPAPI int php_ini_has_per_dir_config(void)
PHPAPI void php_ini_activate_per_host_config(const char *host, size_t host_len)
PHPAPI void php_ini_activate_per_dir_config(char *path, size_t path_len)
#define STD_PHP_INI_ENTRY
#define STD_PHP_INI_BOOLEAN
#define PHP_INI_STAGE_HTACCESS
PHPAPI void php_ini_builder_define(struct php_ini_builder *b, const char *arg)
#define PHPWRITE_H(str, str_len)
unsigned char key[REFLECTION_KEY_LEN]
PHPAPI void(* php_load_environment_variables)(zval *array_ptr)
PHPAPI void(* php_import_environment_variables)(zval *array_ptr)
PHPAPI void php_register_variable_safe(const char *var, const char *strval, size_t str_len, zval *track_vars_array)
bool fcgi_logging_request_started
HashTable user_config_cache
char * redirect_status_env
PHPAPI size_t php_raw_url_decode(char *str, size_t len)
ZEND_API HashTable module_registry
#define zend_parse_parameters_none()
#define estrndup(s, length)
#define pemalloc(size, persistent)
strncmp(string $string1, string $string2, int $length)
strcmp(string $string1, string $string2)
ZEND_API size_t zend_dirname(char *path, size_t len)
#define ZEND_COMPILE_EXTENDED_INFO
ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle)
#define strncasecmp(s1, s2, n)
#define strcasecmp(s1, s2)
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
ZEND_API zend_llist zend_extensions
struct _zend_extension zend_extension
ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht)
ZEND_API void ZEND_FASTCALL zend_hash_clean(HashTable *ht)
ZEND_API void ZEND_FASTCALL zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor)
ZEND_API void ZEND_FASTCALL zend_array_destroy(HashTable *ht)
ZEND_API HashTable *ZEND_FASTCALL zend_array_dup(HashTable *source)
#define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent)
#define ZEND_HASH_MAP_FOREACH_PTR(ht, _ptr)
#define ZEND_HASH_FOREACH_END()
#define ZEND_INI_PARSER_ENTRY
void(* zend_ini_parser_cb_t)(zval *arg1, zval *arg2, zval *arg3, int callback_type, void *arg)
#define UNREGISTER_INI_ENTRIES()
#define REGISTER_INI_ENTRIES()
#define DISPLAY_INI_ENTRIES()
ZEND_API zend_result zend_parse_ini_string(const char *str, bool unbuffered_errors, int scanner_mode, zend_ini_parser_cb_t ini_parser_cb, void *arg)
struct _zend_file_handle zend_file_handle
#define ZEND_INI_SCANNER_NORMAL
ZEND_API void zend_llist_destroy(zend_llist *l)
ZEND_API void zend_llist_copy(zend_llist *dst, zend_llist *src)
ZEND_API void * zend_llist_get_next_ex(zend_llist *l, zend_llist_position *pos)
ZEND_API void zend_llist_sort(zend_llist *l, llist_compare_func_t comp_func)
ZEND_API void zend_llist_apply(zend_llist *l, llist_apply_func_t func)
ZEND_API void * zend_llist_get_first_ex(zend_llist *l, zend_llist_position *pos)
struct _zend_llist_element zend_llist_element
zend_llist_element * zend_llist_position
void(* llist_apply_func_t)(void *)
struct _zend_llist zend_llist
#define STANDARD_MODULE_HEADER
struct _zend_module_entry zend_module_entry
#define STANDARD_MODULE_PROPERTIES
ZEND_API void ZEND_FASTCALL zend_str_tolower(char *str, size_t length)
#define zend_quiet_write(...)
#define EXPECTED(condition)
#define UNEXPECTED(condition)
#define zend_signal_startup()
#define Z_STRVAL_P(zval_p)
struct _zend_array HashTable
CWD_API char * tsrm_realpath(const char *path, char *real_path)
#define IS_ABSOLUTE_PATH(path, len)
void zlog_set_external_logger(void(*logger)(int, char *, size_t))
void vzlog(const char *function, int line, int flags, const char *fmt, va_list args)
#define zlog_msg(flags, prefix, msg)