From: Michael <heluecht@pirati.ca>
Date: Tue, 12 Feb 2019 06:42:45 +0000 (+0000)
Subject: Ensure that "strtotime" returns the correct timestamp
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f6e8246e757cc8dad7b9ddef3edbe795a82265b6;p=friendica.git

Ensure that "strtotime" returns the correct timestamp
---

diff --git a/mod/worker.php b/mod/worker.php
index af778f8d64..1afbfe81c1 100644
--- a/mod/worker.php
+++ b/mod/worker.php
@@ -17,6 +17,9 @@ function worker_init()
 		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.
 	// So we just wake up the worker if it sleeps.
 	if (function_exists("proc_open")) {
diff --git a/src/Core/Worker.php b/src/Core/Worker.php
index 5deb33ab64..a6fee3bb6b 100644
--- a/src/Core/Worker.php
+++ b/src/Core/Worker.php
@@ -40,6 +40,9 @@ class Worker
 	{
 		$a = \get_app();
 
+		// Ensure that all "strtotime" operations do run timezone independent
+		date_default_timezone_set('UTC');
+
 		self::$up_start = microtime(true);
 
 		// 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]);
 
 				// 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 = (strtotime(DateTimeFormat::utcNow()) - strtotime($entry["executed"])) / 60;
+				$duration = (time() - strtotime($entry["executed"])) / 60;
 				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.");
 					posix_kill($entry["pid"], SIGTERM);