You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

676 lines
19 KiB

23 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2008 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Sascha Schumann <sascha@schumann.cx> |
  16. | Parts based on Apache 1.3 SAPI module by |
  17. | Rasmus Lerdorf and Zeev Suraski |
  18. +----------------------------------------------------------------------+
  19. */
  20. /* $Id$ */
  21. #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
  22. #include "php.h"
  23. #include "php_main.h"
  24. #include "php_ini.h"
  25. #include "php_variables.h"
  26. #include "SAPI.h"
  27. #include <fcntl.h>
  28. #include "ext/standard/php_smart_str.h"
  29. #ifndef NETWARE
  30. #include "ext/standard/php_standard.h"
  31. #else
  32. #include "ext/standard/basic_functions.h"
  33. #endif
  34. #include "apr_strings.h"
  35. #include "ap_config.h"
  36. #include "util_filter.h"
  37. #include "httpd.h"
  38. #include "http_config.h"
  39. #include "http_request.h"
  40. #include "http_core.h"
  41. #include "http_protocol.h"
  42. #include "http_log.h"
  43. #include "http_main.h"
  44. #include "util_script.h"
  45. #include "http_core.h"
  46. #include "ap_mpm.h"
  47. #include "php_apache.h"
  48. /* UnixWare and Netware define shutdown to _shutdown, which causes problems later
  49. * on when using a structure member named shutdown. Since this source
  50. * file does not use the system call shutdown, it is safe to #undef it.K
  51. */
  52. #undef shutdown
  53. #define PHP_MAGIC_TYPE "application/x-httpd-php"
  54. #define PHP_SOURCE_MAGIC_TYPE "application/x-httpd-php-source"
  55. #define PHP_SCRIPT "php6-script"
  56. /* A way to specify the location of the php.ini dir in an apache directive */
  57. char *apache2_php_ini_path_override = NULL;
  58. static int
  59. php_apache_sapi_ub_write(const char *str, uint str_length TSRMLS_DC)
  60. {
  61. request_rec *r;
  62. php_struct *ctx;
  63. ctx = SG(server_context);
  64. r = ctx->r;
  65. if (ap_rwrite(str, str_length, r) < 0) {
  66. php_handle_aborted_connection();
  67. }
  68. return str_length; /* we always consume all the data passed to us. */
  69. }
  70. static int
  71. php_apache_sapi_header_handler(sapi_header_struct *sapi_header,sapi_headers_struct *sapi_headers TSRMLS_DC)
  72. {
  73. php_struct *ctx;
  74. char *val, *ptr;
  75. ctx = SG(server_context);
  76. val = strchr(sapi_header->header, ':');
  77. if (!val) {
  78. sapi_free_header(sapi_header);
  79. return 0;
  80. }
  81. ptr = val;
  82. *val = '\0';
  83. do {
  84. val++;
  85. } while (*val == ' ');
  86. if (!strcasecmp(sapi_header->header, "content-type")) {
  87. if (ctx->content_type) {
  88. efree(ctx->content_type);
  89. }
  90. ctx->content_type = estrdup(val);
  91. } else if (sapi_header->replace) {
  92. apr_table_set(ctx->r->headers_out, sapi_header->header, val);
  93. } else {
  94. apr_table_add(ctx->r->headers_out, sapi_header->header, val);
  95. }
  96. *ptr = ':';
  97. return SAPI_HEADER_ADD;
  98. }
  99. static int
  100. php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
  101. {
  102. php_struct *ctx = SG(server_context);
  103. const char *sline = SG(sapi_headers).http_status_line;
  104. ctx->r->status = SG(sapi_headers).http_response_code;
  105. /* httpd requires that r->status_line is set to the first digit of
  106. * the status-code: */
  107. if (sline && strlen(sline) > 12 && strncmp(sline, "HTTP/1.", 7) == 0 && sline[8] == ' ') {
  108. ctx->r->status_line = apr_pstrdup(ctx->r->pool, sline + 9);
  109. ctx->r->proto_num = 1000 + (sline[7]-'0');
  110. if ((sline[7]-'0') == 0) {
  111. apr_table_set(ctx->r->subprocess_env, "force-response-1.0", "true");
  112. }
  113. }
  114. /* call ap_set_content_type only once, else each time we call it,
  115. configured output filters for that content type will be added */
  116. if (!ctx->content_type) {
  117. ctx->content_type = sapi_get_default_content_type(TSRMLS_C);
  118. }
  119. ap_set_content_type(ctx->r, apr_pstrdup(ctx->r->pool, ctx->content_type));
  120. efree(ctx->content_type);
  121. ctx->content_type = NULL;
  122. return SAPI_HEADER_SENT_SUCCESSFULLY;
  123. }
  124. static int
  125. php_apache_sapi_read_post(char *buf, uint count_bytes TSRMLS_DC)
  126. {
  127. apr_size_t len, tlen=0;
  128. php_struct *ctx = SG(server_context);
  129. request_rec *r;
  130. apr_bucket_brigade *brigade;
  131. r = ctx->r;
  132. brigade = ctx->brigade;
  133. len = count_bytes;
  134. /*
  135. * This loop is needed because ap_get_brigade() can return us partial data
  136. * which would cause premature termination of request read. Therefor we
  137. * need to make sure that if data is available we fill the buffer completely.
  138. */
  139. while (ap_get_brigade(r->input_filters, brigade, AP_MODE_READBYTES, APR_BLOCK_READ, len) == APR_SUCCESS) {
  140. apr_brigade_flatten(brigade, buf, &len);
  141. apr_brigade_cleanup(brigade);
  142. tlen += len;
  143. if (tlen == count_bytes || !len) {
  144. break;
  145. }
  146. buf += len;
  147. len = count_bytes - tlen;
  148. }
  149. return tlen;
  150. }
  151. static struct stat*
  152. php_apache_sapi_get_stat(TSRMLS_D)
  153. {
  154. php_struct *ctx = SG(server_context);
  155. ctx->finfo.st_uid = ctx->r->finfo.user;
  156. ctx->finfo.st_gid = ctx->r->finfo.group;
  157. ctx->finfo.st_dev = ctx->r->finfo.device;
  158. ctx->finfo.st_ino = ctx->r->finfo.inode;
  159. #if defined(NETWARE) && defined(CLIB_STAT_PATCH)
  160. ctx->finfo.st_atime.tv_sec = apr_time_sec(ctx->r->finfo.atime);
  161. ctx->finfo.st_mtime.tv_sec = apr_time_sec(ctx->r->finfo.mtime);
  162. ctx->finfo.st_ctime.tv_sec = apr_time_sec(ctx->r->finfo.ctime);
  163. #else
  164. ctx->finfo.st_atime = apr_time_sec(ctx->r->finfo.atime);
  165. ctx->finfo.st_mtime = apr_time_sec(ctx->r->finfo.mtime);
  166. ctx->finfo.st_ctime = apr_time_sec(ctx->r->finfo.ctime);
  167. #endif
  168. ctx->finfo.st_size = ctx->r->finfo.size;
  169. ctx->finfo.st_nlink = ctx->r->finfo.nlink;
  170. return &ctx->finfo;
  171. }
  172. static char *
  173. php_apache_sapi_read_cookies(TSRMLS_D)
  174. {
  175. php_struct *ctx = SG(server_context);
  176. const char *http_cookie;
  177. http_cookie = apr_table_get(ctx->r->headers_in, "cookie");
  178. /* The SAPI interface should use 'const char *' */
  179. return (char *) http_cookie;
  180. }
  181. static char *
  182. php_apache_sapi_getenv(char *name, size_t name_len TSRMLS_DC)
  183. {
  184. php_struct *ctx = SG(server_context);
  185. const char *env_var;
  186. env_var = apr_table_get(ctx->r->subprocess_env, name);
  187. return (char *) env_var;
  188. }
  189. static void
  190. php_apache_sapi_register_variables(zval *track_vars_array TSRMLS_DC)
  191. {
  192. php_struct *ctx = SG(server_context);
  193. const apr_array_header_t *arr = apr_table_elts(ctx->r->subprocess_env);
  194. char *key, *val;
  195. int new_val_len;
  196. APR_ARRAY_FOREACH_OPEN(arr, key, val)
  197. if (!val) {
  198. val = "";
  199. }
  200. if (sapi_module.input_filter(PARSE_SERVER, key, &val, strlen(val), &new_val_len TSRMLS_CC)) {
  201. php_register_variable_safe(key, val, new_val_len, track_vars_array TSRMLS_CC);
  202. }
  203. APR_ARRAY_FOREACH_CLOSE()
  204. if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &ctx->r->uri, strlen(ctx->r->uri), &new_val_len TSRMLS_CC)) {
  205. php_register_variable_safe("PHP_SELF", ctx->r->uri, new_val_len, track_vars_array TSRMLS_CC);
  206. }
  207. }
  208. static void
  209. php_apache_sapi_flush(void *server_context)
  210. {
  211. php_struct *ctx;
  212. request_rec *r;
  213. TSRMLS_FETCH();
  214. ctx = server_context;
  215. /* If we haven't registered a server_context yet,
  216. * then don't bother flushing. */
  217. if (!server_context) {
  218. return;
  219. }
  220. r = ctx->r;
  221. sapi_send_headers(TSRMLS_C);
  222. r->status = SG(sapi_headers).http_response_code;
  223. SG(headers_sent) = 1;
  224. if (ap_rflush(r) < 0 || r->connection->aborted) {
  225. php_handle_aborted_connection();
  226. }
  227. }
  228. static void php_apache_sapi_log_message(char *msg)
  229. {
  230. php_struct *ctx;
  231. TSRMLS_FETCH();
  232. ctx = SG(server_context);
  233. if (ctx == NULL) { /* we haven't initialized our ctx yet, oh well */
  234. ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, 0, NULL, "%s", msg);
  235. } else {
  236. ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, ctx->r, "%s", msg);
  237. }
  238. }
  239. static void php_apache_sapi_log_message_ex(char *msg, request_rec *r)
  240. {
  241. if (r) {
  242. ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, msg, r->filename);
  243. } else {
  244. php_apache_sapi_log_message(msg);
  245. }
  246. }
  247. static time_t php_apache_sapi_get_request_time(TSRMLS_D) {
  248. php_struct *ctx = SG(server_context);
  249. return apr_time_sec(ctx->r->request_time);
  250. }
  251. extern zend_module_entry php_apache_module;
  252. static int php_apache2_startup(sapi_module_struct *sapi_module)
  253. {
  254. if (php_module_startup(sapi_module, &php_apache_module, 1)==FAILURE) {
  255. return FAILURE;
  256. }
  257. return SUCCESS;
  258. }
  259. static sapi_module_struct apache2_sapi_module = {
  260. "apache2handler",
  261. "Apache 2.0 Handler",
  262. php_apache2_startup, /* startup */
  263. php_module_shutdown_wrapper, /* shutdown */
  264. NULL, /* activate */
  265. NULL, /* deactivate */
  266. php_apache_sapi_ub_write, /* unbuffered write */
  267. php_apache_sapi_flush, /* flush */
  268. php_apache_sapi_get_stat, /* get uid */
  269. php_apache_sapi_getenv, /* getenv */
  270. php_error, /* error handler */
  271. php_apache_sapi_header_handler, /* header handler */
  272. php_apache_sapi_send_headers, /* send headers handler */
  273. NULL, /* send header handler */
  274. php_apache_sapi_read_post, /* read POST data */
  275. php_apache_sapi_read_cookies, /* read Cookies */
  276. php_apache_sapi_register_variables,
  277. php_apache_sapi_log_message, /* Log message */
  278. php_apache_sapi_get_request_time, /* Request Time */
  279. NULL, /* Child terminate */
  280. STANDARD_SAPI_MODULE_PROPERTIES
  281. };
  282. static apr_status_t php_apache_server_shutdown(void *tmp)
  283. {
  284. apache2_sapi_module.shutdown(&apache2_sapi_module);
  285. sapi_shutdown();
  286. #ifdef ZTS
  287. tsrm_shutdown();
  288. #endif
  289. return APR_SUCCESS;
  290. }
  291. static apr_status_t php_apache_child_shutdown(void *tmp)
  292. {
  293. apache2_sapi_module.shutdown(&apache2_sapi_module);
  294. #if defined(ZTS) && !defined(PHP_WIN32)
  295. tsrm_shutdown();
  296. #endif
  297. return APR_SUCCESS;
  298. }
  299. static void php_apache_add_version(apr_pool_t *p)
  300. {
  301. TSRMLS_FETCH();
  302. if (PG(expose_php)) {
  303. ap_add_version_component(p, "PHP/" PHP_VERSION);
  304. }
  305. }
  306. static int php_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
  307. {
  308. #ifndef ZTS
  309. int threaded_mpm;
  310. ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm);
  311. if(threaded_mpm) {
  312. ap_log_error(APLOG_MARK, APLOG_CRIT, 0, 0, "Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP.");
  313. return DONE;
  314. }
  315. #endif
  316. /* When this is NULL, apache won't override the hard-coded default
  317. * php.ini path setting. */
  318. apache2_php_ini_path_override = NULL;
  319. return OK;
  320. }
  321. static int
  322. php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
  323. {
  324. void *data = NULL;
  325. const char *userdata_key = "apache2hook_post_config";
  326. /* Apache will load, unload and then reload a DSO module. This
  327. * prevents us from starting PHP until the second load. */
  328. apr_pool_userdata_get(&data, userdata_key, s->process->pool);
  329. if (data == NULL) {
  330. /* We must use set() here and *not* setn(), otherwise the
  331. * static string pointed to by userdata_key will be mapped
  332. * to a different location when the DSO is reloaded and the
  333. * pointers won't match, causing get() to return NULL when
  334. * we expected it to return non-NULL. */
  335. apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool);
  336. return OK;
  337. }
  338. /* Set up our overridden path. */
  339. if (apache2_php_ini_path_override) {
  340. apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override;
  341. }
  342. #ifdef ZTS
  343. tsrm_startup(1, 1, 0, NULL);
  344. #endif
  345. sapi_startup(&apache2_sapi_module);
  346. apache2_sapi_module.startup(&apache2_sapi_module);
  347. apr_pool_cleanup_register(pconf, NULL, php_apache_server_shutdown, apr_pool_cleanup_null);
  348. php_apache_add_version(pconf);
  349. return OK;
  350. }
  351. static apr_status_t php_server_context_cleanup(void *data_)
  352. {
  353. void **data = data_;
  354. *data = NULL;
  355. return APR_SUCCESS;
  356. }
  357. static int php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC)
  358. {
  359. char *content_length;
  360. const char *auth;
  361. SG(sapi_headers).http_response_code = !r->status ? HTTP_OK : r->status;
  362. SG(request_info).content_type = apr_table_get(r->headers_in, "Content-Type");
  363. SG(request_info).query_string = apr_pstrdup(r->pool, r->args);
  364. SG(request_info).request_method = r->method;
  365. SG(request_info).proto_num = r->proto_num;
  366. SG(request_info).request_uri = apr_pstrdup(r->pool, r->uri);
  367. SG(request_info).path_translated = apr_pstrdup(r->pool, r->filename);
  368. r->no_local_copy = 1;
  369. content_length = (char *) apr_table_get(r->headers_in, "Content-Length");
  370. SG(request_info).content_length = (content_length ? atoi(content_length) : 0);
  371. apr_table_unset(r->headers_out, "Content-Length");
  372. apr_table_unset(r->headers_out, "Last-Modified");
  373. apr_table_unset(r->headers_out, "Expires");
  374. apr_table_unset(r->headers_out, "ETag");
  375. auth = apr_table_get(r->headers_in, "Authorization");
  376. php_handle_auth_data(auth TSRMLS_CC);
  377. ctx->r->user = apr_pstrdup(ctx->r->pool, SG(request_info).auth_user);
  378. return php_request_startup(TSRMLS_C);
  379. }
  380. static void php_apache_request_dtor(request_rec *r TSRMLS_DC)
  381. {
  382. php_request_shutdown(NULL);
  383. }
  384. static void php_apache_ini_dtor(request_rec *r, request_rec *p TSRMLS_DC)
  385. {
  386. if (strcmp(r->protocol, "INCLUDED")) {
  387. zend_try { zend_ini_deactivate(TSRMLS_C); } zend_end_try();
  388. } else {
  389. typedef struct {
  390. HashTable config;
  391. } php_conf_rec;
  392. char *str;
  393. uint str_len;
  394. php_conf_rec *c = ap_get_module_config(r->per_dir_config, &php6_module);
  395. for (zend_hash_internal_pointer_reset(&c->config);
  396. zend_hash_get_current_key_ex(&c->config, &str, &str_len, NULL, 0, NULL) == HASH_KEY_IS_STRING;
  397. zend_hash_move_forward(&c->config)
  398. ) {
  399. zend_restore_ini_entry(str, str_len, ZEND_INI_STAGE_SHUTDOWN);
  400. }
  401. }
  402. if (p) {
  403. ((php_struct *)SG(server_context))->r = p;
  404. } else {
  405. apr_pool_cleanup_run(r->pool, (void *)&SG(server_context), php_server_context_cleanup);
  406. }
  407. }
  408. static int php_handler(request_rec *r)
  409. {
  410. php_struct * volatile ctx;
  411. void *conf;
  412. apr_bucket_brigade * volatile brigade;
  413. apr_bucket *bucket;
  414. apr_status_t rv;
  415. request_rec * volatile parent_req = NULL;
  416. TSRMLS_FETCH();
  417. #define PHPAP_INI_OFF php_apache_ini_dtor(r, parent_req TSRMLS_CC);
  418. conf = ap_get_module_config(r->per_dir_config, &php6_module);
  419. /* apply_config() needs r in some cases, so allocate server_context early */
  420. ctx = SG(server_context);
  421. if (ctx == NULL || (ctx && ctx->request_processed && !strcmp(r->protocol, "INCLUDED"))) {
  422. normal:
  423. ctx = SG(server_context) = apr_pcalloc(r->pool, sizeof(*ctx));
  424. /* register a cleanup so we clear out the SG(server_context)
  425. * after each request. Note: We pass in the pointer to the
  426. * server_context in case this is handled by a different thread.
  427. */
  428. apr_pool_cleanup_register(r->pool, (void *)&SG(server_context), php_server_context_cleanup, apr_pool_cleanup_null);
  429. ctx->r = r;
  430. ctx = NULL; /* May look weird to null it here, but it is to catch the right case in the first_try later on */
  431. } else {
  432. parent_req = ctx->r;
  433. ctx->r = r;
  434. }
  435. apply_config(conf);
  436. if (strcmp(r->handler, PHP_MAGIC_TYPE) && strcmp(r->handler, PHP_SOURCE_MAGIC_TYPE) && strcmp(r->handler, PHP_SCRIPT)) {
  437. /* Check for xbithack in this case. */
  438. if (!AP2(xbithack) || strcmp(r->handler, "text/html") || !(r->finfo.protection & APR_UEXECUTE)) {
  439. PHPAP_INI_OFF;
  440. return DECLINED;
  441. }
  442. }
  443. /* Give a 404 if PATH_INFO is used but is explicitly disabled in
  444. * the configuration; default behaviour is to accept. */
  445. if (r->used_path_info == AP_REQ_REJECT_PATH_INFO
  446. && r->path_info && r->path_info[0]) {
  447. PHPAP_INI_OFF;
  448. return HTTP_NOT_FOUND;
  449. }
  450. /* handle situations where user turns the engine off */
  451. if (!AP2(engine)) {
  452. PHPAP_INI_OFF;
  453. return DECLINED;
  454. }
  455. if (r->finfo.filetype == 0) {
  456. php_apache_sapi_log_message_ex("script '%s' not found or unable to stat", r);
  457. PHPAP_INI_OFF;
  458. return HTTP_NOT_FOUND;
  459. }
  460. if (r->finfo.filetype == APR_DIR) {
  461. php_apache_sapi_log_message_ex("attempt to invoke directory '%s' as script", r);
  462. PHPAP_INI_OFF;
  463. return HTTP_FORBIDDEN;
  464. }
  465. /* Setup the CGI variables if this is the main request */
  466. if (r->main == NULL ||
  467. /* .. or if the sub-request environment differs from the main-request. */
  468. r->subprocess_env != r->main->subprocess_env
  469. ) {
  470. /* setup standard CGI variables */
  471. ap_add_common_vars(r);
  472. ap_add_cgi_vars(r);
  473. }
  474. zend_first_try {
  475. if (ctx == NULL) {
  476. brigade = apr_brigade_create(r->pool, r->connection->bucket_alloc);
  477. ctx = SG(server_context);
  478. ctx->brigade = brigade;
  479. if (php_apache_request_ctor(r, ctx TSRMLS_CC)!=SUCCESS) {
  480. zend_bailout();
  481. }
  482. } else {
  483. if (!parent_req) {
  484. parent_req = ctx->r;
  485. }
  486. if (parent_req && parent_req->handler &&
  487. strcmp(parent_req->handler, PHP_MAGIC_TYPE) &&
  488. strcmp(parent_req->handler, PHP_SOURCE_MAGIC_TYPE) &&
  489. strcmp(parent_req->handler, PHP_SCRIPT)) {
  490. if (php_apache_request_ctor(r, ctx TSRMLS_CC)!=SUCCESS) {
  491. zend_bailout();
  492. }
  493. }
  494. /*
  495. * check if comming due to ErrorDocument
  496. * We make a special exception of 413 (Invalid POST request) as the invalidity of the request occurs
  497. * during processing of the request by PHP during POST processing. Therefor we need to re-use the exiting
  498. * PHP instance to handle the request rather then creating a new one.
  499. */
  500. if (parent_req && parent_req->status != HTTP_OK && parent_req->status != 413 && strcmp(r->protocol, "INCLUDED")) {
  501. parent_req = NULL;
  502. goto normal;
  503. }
  504. ctx->r = r;
  505. brigade = ctx->brigade;
  506. }
  507. if (AP2(last_modified)) {
  508. ap_update_mtime(r, r->finfo.mtime);
  509. ap_set_last_modified(r);
  510. }
  511. /* Determine if we need to parse the file or show the source */
  512. if (strncmp(r->handler, PHP_SOURCE_MAGIC_TYPE, sizeof(PHP_SOURCE_MAGIC_TYPE) - 1) == 0) {
  513. zend_syntax_highlighter_ini syntax_highlighter_ini;
  514. php_get_highlight_struct(&syntax_highlighter_ini);
  515. highlight_file((char *)r->filename, &syntax_highlighter_ini TSRMLS_CC);
  516. } else {
  517. zend_file_handle zfd;
  518. zfd.type = ZEND_HANDLE_FILENAME;
  519. zfd.filename = (char *) r->filename;
  520. zfd.free_filename = 0;
  521. zfd.opened_path = NULL;
  522. if (!parent_req) {
  523. php_execute_script(&zfd TSRMLS_CC);
  524. } else {
  525. zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &zfd);
  526. }
  527. apr_table_set(r->notes, "mod_php_memory_usage",
  528. apr_psprintf(ctx->r->pool, "%u", zend_memory_peak_usage(1 TSRMLS_CC)));
  529. }
  530. } zend_end_try();
  531. if (!parent_req) {
  532. php_apache_request_dtor(r TSRMLS_CC);
  533. ctx->request_processed = 1;
  534. bucket = apr_bucket_eos_create(r->connection->bucket_alloc);
  535. APR_BRIGADE_INSERT_TAIL(brigade, bucket);
  536. rv = ap_pass_brigade(r->output_filters, brigade);
  537. if (rv != APR_SUCCESS || r->connection->aborted) {
  538. zend_first_try {
  539. php_handle_aborted_connection();
  540. } zend_end_try();
  541. }
  542. apr_brigade_cleanup(brigade);
  543. } else {
  544. ctx->r = parent_req;
  545. }
  546. return OK;
  547. }
  548. static void php_apache_child_init(apr_pool_t *pchild, server_rec *s)
  549. {
  550. apr_pool_cleanup_register(pchild, NULL, php_apache_child_shutdown, apr_pool_cleanup_null);
  551. }
  552. void php_ap2_register_hook(apr_pool_t *p)
  553. {
  554. ap_hook_pre_config(php_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
  555. ap_hook_post_config(php_apache_server_startup, NULL, NULL, APR_HOOK_MIDDLE);
  556. ap_hook_handler(php_handler, NULL, NULL, APR_HOOK_MIDDLE);
  557. ap_hook_child_init(php_apache_child_init, NULL, NULL, APR_HOOK_MIDDLE);
  558. }
  559. /*
  560. * Local variables:
  561. * tab-width: 4
  562. * c-basic-offset: 4
  563. * End:
  564. * vim600: sw=4 ts=4 fdm=marker
  565. * vim<600: sw=4 ts=4
  566. */