Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the environment variable TZ effective in Docker and default to using the UTC timezone. #628

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ RUN apt-get update && apt-get install -y \
&& docker-php-ext-install -j$(nproc) gd pdo pdo_mysql pdo_pgsql pgsql \
&& rm -rf /var/lib/apt/lists/*

# Set the timezone
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Prepare files and folders
RUN mkdir -p /speedtest/

Expand Down
22 changes: 17 additions & 5 deletions results/telemetry_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
require_once 'idObfuscation.php';

define('TELEMETRY_SETTINGS_FILE', 'telemetry_settings.php');

$tz = getenv('TZ');
//Set timezone to UTC if Environment variables are not set
if ($tz !== false) {
// If the TZ environment variable exists, set the default timezone for PHP to its value
date_default_timezone_set($tz);
} else {
// If the TZ environment variable does not exist, set a default timezone or handle the error
// Set it to the UTC timezone
date_default_timezone_set('UTC');
}
/**
* @return PDO|false
*/
Expand Down Expand Up @@ -184,15 +193,18 @@ function insertSpeedtestUser($ip, $ispinfo, $extra, $ua, $lang, $dl, $ul, $ping,
}

try {
$currentTimestamp = new DateTime('now'); // This will automatically use the timezone configured in PHP
$formattedTimestamp = $currentTimestamp->format('Y-m-d H:i:s');

$stmt = $pdo->prepare(
'INSERT INTO speedtest_users
(ip,ispinfo,extra,ua,lang,dl,ul,ping,jitter,log)
VALUES (?,?,?,?,?,?,?,?,?,?)'
(ip,ispinfo,extra,ua,lang,dl,ul,ping,jitter,log,timestamp)
VALUES (?,?,?,?,?,?,?,?,?,?,?)' // Added the timestamp field here
);
$stmt->execute([
$ip, $ispinfo, $extra, $ua, $lang, $dl, $ul, $ping, $jitter, $log
$ip, $ispinfo, $extra, $ua, $lang, $dl, $ul, $ping, $jitter, $log, $formattedTimestamp // Added $formattedTimestamp in the execute parameters
]);
$id = $pdo->lastInsertId();
$id = $pdo->lastInsertId();
} catch (Exception $e) {
if($returnExceptionOnError){
return $e;
Expand Down