summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-09-17 07:11:59 +0000
committerDries Buytaert <dries@buytaert.net>2008-09-17 07:11:59 +0000
commit7f29b142770cba60259a22f3760e2376b8e79790 (patch)
treed9ff4c7dfb29dfafb442c2cd1f2e91b2592e63bc /includes
parent6f8b5f9a5baaea6874ffe050ba0210b680070140 (diff)
downloadbrdo-7f29b142770cba60259a22f3760e2376b8e79790.tar.gz
brdo-7f29b142770cba60259a22f3760e2376b8e79790.tar.bz2
- Patch #305645 by pwolanin: ['REQUEST_TIME'] -> REQUEST_TIME. Improved developer experience.
Diffstat (limited to 'includes')
-rw-r--r--includes/bootstrap.inc7
-rw-r--r--includes/cache.inc14
-rw-r--r--includes/common.inc14
-rw-r--r--includes/file.inc2
-rw-r--r--includes/form.inc12
-rw-r--r--includes/session.inc10
6 files changed, 32 insertions, 27 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 850ea2b0c..878af3c82 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -181,6 +181,11 @@ define('LANGUAGE_NEGOTIATION_PATH', 2);
define('LANGUAGE_NEGOTIATION_DOMAIN', 3);
/**
+ * For convenience, define a short form of the request time global.
+ */
+define ('REQUEST_TIME', $_SERVER['REQUEST_TIME']);
+
+/**
* Start the timer with the specified name. If you start and stop
* the same timer multiple times, the measured intervals will be
* accumulated.
@@ -816,7 +821,7 @@ function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NO
'request_uri' => $base_root . request_uri(),
'referer' => $_SERVER['HTTP_REFERER'],
'ip' => ip_address(),
- 'timestamp' => $_SERVER['REQUEST_TIME'],
+ 'timestamp' => REQUEST_TIME,
);
// Call the logging hooks to log/process the message
diff --git a/includes/cache.inc b/includes/cache.inc
index 245726ff6..62cbb2846 100644
--- a/includes/cache.inc
+++ b/includes/cache.inc
@@ -19,7 +19,7 @@ function cache_get($cid, $table = 'cache') {
// Garbage collection necessary when enforcing a minimum cache lifetime
$cache_flush = variable_get('cache_flush', 0);
- if ($cache_flush && ($cache_flush + variable_get('cache_lifetime', 0) <= $_SERVER['REQUEST_TIME'])) {
+ if ($cache_flush && ($cache_flush + variable_get('cache_lifetime', 0) <= REQUEST_TIME)) {
// Reset the variable immediately to prevent a meltdown in heavy load situations.
variable_set('cache_flush', 0);
// Time to flush old cache data
@@ -104,7 +104,7 @@ function cache_get($cid, $table = 'cache') {
function cache_set($cid, $data, $table = 'cache', $expire = CACHE_PERMANENT, $headers = NULL) {
$fields = array(
'serialized' => 0,
- 'created' => $_SERVER['REQUEST_TIME'],
+ 'created' => REQUEST_TIME,
'expire' => $expire,
'headers' => $headers,
);
@@ -155,23 +155,23 @@ function cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE) {
// will be saved into the sessions table by _sess_write(). We then
// simulate that the cache was flushed for this user by not returning
// cached data that was cached before the timestamp.
- $user->cache = $_SERVER['REQUEST_TIME'];
+ $user->cache = REQUEST_TIME;
$cache_flush = variable_get('cache_flush', 0);
if ($cache_flush == 0) {
// This is the first request to clear the cache, start a timer.
- variable_set('cache_flush', $_SERVER['REQUEST_TIME']);
+ variable_set('cache_flush', REQUEST_TIME);
}
- else if ($_SERVER['REQUEST_TIME'] > ($cache_flush + variable_get('cache_lifetime', 0))) {
+ else if (REQUEST_TIME > ($cache_flush + variable_get('cache_lifetime', 0))) {
// Clear the cache for everyone, cache_flush_delay seconds have
// passed since the first request to clear the cache.
- db_query("DELETE FROM {" . $table . "} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, $_SERVER['REQUEST_TIME']);
+ db_query("DELETE FROM {" . $table . "} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, REQUEST_TIME);
variable_set('cache_flush', 0);
}
}
else {
// No minimum cache lifetime, flush all temporary cache entries now.
- db_query("DELETE FROM {" . $table . "} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, $_SERVER['REQUEST_TIME']);
+ db_query("DELETE FROM {" . $table . "} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, REQUEST_TIME);
}
}
else {
diff --git a/includes/common.inc b/includes/common.inc
index 69227435e..2336e5fda 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -903,7 +903,7 @@ function valid_url($url, $absolute = FALSE) {
* The name of an event.
*/
function flood_register_event($name) {
- db_query("INSERT INTO {flood} (event, hostname, timestamp) VALUES ('%s', '%s', %d)", $name, ip_address(), $_SERVER['REQUEST_TIME']);
+ db_query("INSERT INTO {flood} (event, hostname, timestamp) VALUES ('%s', '%s', %d)", $name, ip_address(), REQUEST_TIME);
}
/**
@@ -920,7 +920,7 @@ function flood_register_event($name) {
* True if the user did not exceed the hourly threshold. False otherwise.
*/
function flood_is_allowed($name, $threshold) {
- $number = db_result(db_query("SELECT COUNT(*) FROM {flood} WHERE event = '%s' AND hostname = '%s' AND timestamp > %d", $name, ip_address(), $_SERVER['REQUEST_TIME'] - 3600));
+ $number = db_result(db_query("SELECT COUNT(*) FROM {flood} WHERE event = '%s' AND hostname = '%s' AND timestamp > %d", $name, ip_address(), REQUEST_TIME - 3600));
return ($number < $threshold ? TRUE : FALSE);
}
@@ -2104,7 +2104,7 @@ function drupal_get_js($scope = 'header', $javascript = NULL) {
// browser-caching. The string changes on every update or full cache
// flush, forcing browsers to load a new copy of the files, as the
// URL changed. Files that should not be cached (see drupal_add_js())
- // get $_SERVER['REQUEST_TIME'] as query-string instead, to enforce reload on every
+ // get REQUEST_TIME as query-string instead, to enforce reload on every
// page request.
$query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1);
@@ -2131,7 +2131,7 @@ function drupal_get_js($scope = 'header', $javascript = NULL) {
// Additionally, go through any remaining scripts if JS preprocessing is on and output the non-cached ones.
foreach ($data as $path => $info) {
if (!$info['preprocess'] || !$is_writable || !$preprocess_js) {
- $no_preprocess[$type] .= '<script type="text/javascript"' . ($info['defer'] ? ' defer="defer"' : '') . ' src="' . base_path() . $path . ($info['cache'] ? $query_string : '?' . $_SERVER['REQUEST_TIME']) . "\"></script>\n";
+ $no_preprocess[$type] .= '<script type="text/javascript"' . ($info['defer'] ? ' defer="defer"' : '') . ' src="' . base_path() . $path . ($info['cache'] ? $query_string : '?' . REQUEST_TIME) . "\"></script>\n";
}
else {
$files[$path] = $info;
@@ -2583,7 +2583,7 @@ function drupal_cron_run() {
$semaphore = variable_get('cron_semaphore', FALSE);
if ($semaphore) {
- if ($_SERVER['REQUEST_TIME'] - $semaphore > 3600) {
+ if (REQUEST_TIME - $semaphore > 3600) {
// Either cron has been running for more than an hour or the semaphore
// was not reset due to a database error.
watchdog('cron', 'Cron has been running for more than an hour and is most likely stuck.', array(), WATCHDOG_ERROR);
@@ -2601,13 +2601,13 @@ function drupal_cron_run() {
register_shutdown_function('drupal_cron_cleanup');
// Lock cron semaphore
- variable_set('cron_semaphore', $_SERVER['REQUEST_TIME']);
+ variable_set('cron_semaphore', REQUEST_TIME);
// Iterate through the modules calling their cron handlers (if any):
module_invoke_all('cron');
// Record cron time
- variable_set('cron_last', $_SERVER['REQUEST_TIME']);
+ variable_set('cron_last', REQUEST_TIME);
watchdog('cron', 'Cron run completed.', array(), WATCHDOG_NOTICE);
// Release cron semaphore
diff --git a/includes/file.inc b/includes/file.inc
index bf14efba9..7696163b0 100644
--- a/includes/file.inc
+++ b/includes/file.inc
@@ -643,7 +643,7 @@ function file_save_upload($source, $validators = array(), $destination = FALSE,
// If we made it this far it's safe to record this file in the database.
$file->status = FILE_STATUS_TEMPORARY;
- $file->timestamp = $_SERVER['REQUEST_TIME'];
+ $file->timestamp = REQUEST_TIME;
drupal_write_record('files', $file);
// Add file to the cache.
diff --git a/includes/form.inc b/includes/form.inc
index d50c9efeb..06252cbf5 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -235,9 +235,9 @@ function form_set_cache($form_build_id, $form, $form_state) {
// 6 hours cache life time for forms should be plenty.
$expire = 21600;
- cache_set('form_' . $form_build_id, $form, 'cache_form', $_SERVER['REQUEST_TIME'] + $expire);
+ cache_set('form_' . $form_build_id, $form, 'cache_form', REQUEST_TIME + $expire);
if (!empty($form_state['storage'])) {
- cache_set('storage_' . $form_build_id, $form_state['storage'], 'cache_form', $_SERVER['REQUEST_TIME'] + $expire);
+ cache_set('storage_' . $form_build_id, $form_state['storage'], 'cache_form', REQUEST_TIME + $expire);
}
}
@@ -1645,9 +1645,9 @@ function theme_date($element) {
function form_process_date($element) {
// Default to current date
if (empty($element['#value'])) {
- $element['#value'] = array('day' => format_date($_SERVER['REQUEST_TIME'], 'custom', 'j'),
- 'month' => format_date($_SERVER['REQUEST_TIME'], 'custom', 'n'),
- 'year' => format_date($_SERVER['REQUEST_TIME'], 'custom', 'Y'));
+ $element['#value'] = array('day' => format_date(REQUEST_TIME, 'custom', 'j'),
+ 'month' => format_date(REQUEST_TIME, 'custom', 'n'),
+ 'year' => format_date(REQUEST_TIME, 'custom', 'Y'));
}
$element['#tree'] = TRUE;
@@ -2483,7 +2483,7 @@ function batch_process($redirect = NULL, $url = NULL) {
// Initiate db storage in order to get a batch id. We have to provide
// at least an empty string for the (not null) 'token' column.
- db_query("INSERT INTO {batch} (token, timestamp) VALUES ('', %d)", $_SERVER['REQUEST_TIME']);
+ db_query("INSERT INTO {batch} (token, timestamp) VALUES ('', %d)", REQUEST_TIME);
$batch['id'] = db_last_insert_id('batch', 'bid');
// Now that we have a batch id, we can generate the redirection link in
diff --git a/includes/session.inc b/includes/session.inc
index 0a64c1d6f..46b5cadd1 100644
--- a/includes/session.inc
+++ b/includes/session.inc
@@ -148,18 +148,18 @@ function _sess_write($key, $value) {
// and gives more useful statistics. We can't eliminate anonymous session
// table rows without breaking "Who's Online" block.
if ($user->uid || $value || count($_COOKIE)) {
- db_query("INSERT INTO {sessions} (sid, uid, cache, hostname, session, timestamp) VALUES ('%s', %d, %d, '%s', '%s', %d)", $key, $user->uid, isset($user->cache) ? $user->cache : 0, ip_address(), $value, $_SERVER['REQUEST_TIME']);
+ db_query("INSERT INTO {sessions} (sid, uid, cache, hostname, session, timestamp) VALUES ('%s', %d, %d, '%s', '%s', %d)", $key, $user->uid, isset($user->cache) ? $user->cache : 0, ip_address(), $value, REQUEST_TIME);
}
}
else {
- db_query("UPDATE {sessions} SET uid = %d, cache = %d, hostname = '%s', session = '%s', timestamp = %d WHERE sid = '%s'", $user->uid, isset($user->cache) ? $user->cache : 0, ip_address(), $value, $_SERVER['REQUEST_TIME'], $key);
+ db_query("UPDATE {sessions} SET uid = %d, cache = %d, hostname = '%s', session = '%s', timestamp = %d WHERE sid = '%s'", $user->uid, isset($user->cache) ? $user->cache : 0, ip_address(), $value, REQUEST_TIME, $key);
if (db_affected_rows()) {
// Last access time is updated no more frequently
// than once every 180 seconds.
// This reduces contention in the users table.
- if ($user->uid && $_SERVER['REQUEST_TIME'] - $user->access > variable_get('session_write_interval', 180)) {
- db_query("UPDATE {users} SET access = %d WHERE uid = %d", $_SERVER['REQUEST_TIME'], $user->uid);
+ if ($user->uid && REQUEST_TIME - $user->access > variable_get('session_write_interval', 180)) {
+ db_query("UPDATE {users} SET access = %d WHERE uid = %d", REQUEST_TIME, $user->uid);
}
}
}
@@ -227,7 +227,7 @@ function _sess_gc($lifetime) {
// for three weeks before deleting them, you need to set gc_maxlifetime
// to '1814400'. At that value, only after a user doesn't log in after
// three weeks (1814400 seconds) will his/her session be removed.
- db_query("DELETE FROM {sessions} WHERE timestamp < %d", $_SERVER['REQUEST_TIME'] - $lifetime);
+ db_query("DELETE FROM {sessions} WHERE timestamp < %d", REQUEST_TIME - $lifetime);
return TRUE;
}