From: Wez Furlong Date: Thu, 17 Apr 2003 16:57:46 +0000 (+0000) Subject: Implement sqlite_busy_timeout() which sets the retry timeout (in milliseconds) X-Git-Tag: RELEASE_0_6~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4eba9b8b467b776ff6c9f11d680ed0907d046066;p=php Implement sqlite_busy_timeout() which sets the retry timeout (in milliseconds) when multiple processes attempt to lock and update the database. --- diff --git a/ext/sqlite/php_sqlite.h b/ext/sqlite/php_sqlite.h index 206e20c7a2..40f72902a8 100644 --- a/ext/sqlite/php_sqlite.h +++ b/ext/sqlite/php_sqlite.h @@ -58,6 +58,8 @@ PHP_FUNCTION(sqlite_last_insert_rowid); PHP_FUNCTION(sqlite_escape_string); +PHP_FUNCTION(sqlite_busy_timeout); + #ifdef ZTS #define SQLITE_G(v) TSRMG(sqlite_globals_id, zend_sqlite_globals *, v) #else diff --git a/ext/sqlite/sqlite.c b/ext/sqlite/sqlite.c index 0a799a71a8..831cff2194 100644 --- a/ext/sqlite/sqlite.c +++ b/ext/sqlite/sqlite.c @@ -56,6 +56,7 @@ function_entry sqlite_functions[] = { PHP_FE(sqlite_field_name, NULL) PHP_FE(sqlite_seek, NULL) PHP_FE(sqlite_escape_string, NULL) + PHP_FE(sqlite_busy_timeout, NULL) {NULL, NULL, NULL} }; @@ -243,12 +244,34 @@ PHP_FUNCTION(sqlite_open) /* register the PHP functions */ sqlite_create_function(db, "php", -1, php_sqlite_function_callback, 0); + + /* set default busy handler; keep retrying up until 1/2 second has passed, + * then fail with a busy status code */ + sqlite_busy_timeout(db, 500); ZEND_REGISTER_RESOURCE(return_value, db, le_sqlite_db); } /* }}} */ +/* {{{ proto void sqlite_busy_timeout(resource db, int ms) + Set busy timeout duration. If ms <= 0, all busy handlers are disabled */ +PHP_FUNCTION(sqlite_busy_timeout) +{ + zval *zdb; + sqlite *db; + long ms; + + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zdb, &ms)) { + return; + } + + ZEND_FETCH_RESOURCE(db, sqlite *, &zdb, -1, "sqlite database", le_sqlite_db); + + sqlite_busy_timeout(db, ms); +} +/* }}} */ + /* {{{ proto void sqlite_close(resource db) Closes an open sqlite database */ PHP_FUNCTION(sqlite_close)