From d3439023d3d32aaeedbc3c421afebff959dcc783 Mon Sep 17 00:00:00 2001 From: Rasmus Lerdorf Date: Sat, 4 Sep 1999 21:10:39 +0000 Subject: [PATCH] Catch a timeout and add user-level interface for connection handling --- ext/standard/basic_functions.c | 57 ++++++++++++++++++++++++++++++++++ ext/standard/basic_functions.h | 5 +++ main/main.c | 1 + 3 files changed, 63 insertions(+) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 1f0c0611b2..9af58daa60 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -335,6 +335,11 @@ function_entry basic_functions[] = { PHP_FE(array_keys, NULL) PHP_FE(array_values, NULL) + PHP_FE(connection_aborted, NULL) + PHP_FE(connection_timeout, NULL) + PHP_FE(connection_status, NULL) + PHP_FE(ignore_user_abort, NULL) + {NULL, NULL, NULL} }; @@ -2337,6 +2342,58 @@ PHP_FUNCTION(defined) } } +/* {{{ proto int connection_aborted(void) + Returns true if client disconnected */ +PHP_FUNCTION(connection_aborted) +{ + RETURN_LONG(PG(connection_status)&PHP_CONNECTION_ABORTED); +} +/* }}} */ + +/* {{{ proto int connection_timeout(void) + Returns true if script timed out */ +PHP_FUNCTION(connection_timeout) +{ + + RETURN_LONG(PG(connection_status)&PHP_CONNECTION_TIMEOUT); +} +/* }}} */ + +/* {{{ proto int connection_status(void) + Returns the connection status bitfield */ +PHP_FUNCTION(connection_status) +{ + + RETURN_LONG(PG(connection_status)); +} +/* }}} */ + +/* {{{ proto int ignore_user_abort(boolean value) + Set whether we want to ignore a user abort event or not */ +PHP_FUNCTION(ignore_user_abort) +{ + pval *arg; + int old_setting; + + old_setting = PG(ignore_user_abort); + switch (ARG_COUNT(ht)) { + case 0: + break; + case 1: + if (getParameters(ht,1,&arg) == FAILURE) { + RETURN_FALSE; + } + convert_to_long(arg); + PG(ignore_user_abort)=arg->value.lval; + break; + default: + WRONG_PARAM_COUNT; + break; + } + RETURN_LONG(old_setting); +} +/* }}} */ + /* {{{ proto bool function_exists(string function_name) Checks if a given function has been defined */ PHP_FUNCTION(function_exists) diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index 20d88ca478..cfd502e4de 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -123,6 +123,11 @@ PHP_FUNCTION(print_r); PHP_FUNCTION(define); PHP_FUNCTION(defined); +PHP_FUNCTION(connection_aborted); +PHP_FUNCTION(connection_timeout); +PHP_FUNCTION(connection_status); +PHP_FUNCTION(ignore_user_abort); + PHP_FUNCTION(function_exists); PHP_FUNCTION(in_array); PHP_FUNCTION(extract); diff --git a/main/main.c b/main/main.c index ad812a039f..b573419841 100644 --- a/main/main.c +++ b/main/main.c @@ -474,6 +474,7 @@ static void php3_timeout(int dummy) php_error(E_ERROR, "Maximum execution time of %d second%s exceeded", php_timeout_seconds, php_timeout_seconds == 1 ? "" : "s"); + PG(connection_status) |= PHP_CONNECTION_TIMEOUT; } #endif -- 2.40.0