Merge pull request #6642 from annando/worker-timezone

Ensure that "strtotime" returns the correct timestamp
This commit is contained in:
Tobias Diekershoff 2019-02-12 08:50:32 +01:00 committed by GitHub
commit 48d5186dce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -17,6 +17,9 @@ function worker_init()
return; return;
} }
// Ensure that all "strtotime" operations do run timezone independent
date_default_timezone_set('UTC');
// We don't need the following lines if we can execute background jobs. // We don't need the following lines if we can execute background jobs.
// So we just wake up the worker if it sleeps. // So we just wake up the worker if it sleeps.
if (function_exists("proc_open")) { if (function_exists("proc_open")) {

View File

@ -40,6 +40,9 @@ class Worker
{ {
$a = \get_app(); $a = \get_app();
// Ensure that all "strtotime" operations do run timezone independent
date_default_timezone_set('UTC');
self::$up_start = microtime(true); self::$up_start = microtime(true);
// At first check the maximum load. We shouldn't continue with a high load // At first check the maximum load. We shouldn't continue with a high load
@ -650,8 +653,7 @@ class Worker
$argv[0] = basename($argv[0]); $argv[0] = basename($argv[0]);
// How long is the process already running? // How long is the process already running?
// For some weird reasons we cannot use "time()" here. It doesn't seem to be in UTC. $duration = (time() - strtotime($entry["executed"])) / 60;
$duration = (strtotime(DateTimeFormat::utcNow()) - strtotime($entry["executed"])) / 60;
if ($duration > $max_duration) { if ($duration > $max_duration) {
Logger::log("Worker process ".$entry["pid"]." (".substr(json_encode($argv), 0, 50).") took more than ".$max_duration." minutes. It will be killed now."); Logger::log("Worker process ".$entry["pid"]." (".substr(json_encode($argv), 0, 50).") took more than ".$max_duration." minutes. It will be killed now.");
posix_kill($entry["pid"], SIGTERM); posix_kill($entry["pid"], SIGTERM);