This topic is locked

Guide 28 - Place the server in a time zone

11/17/2021 7:50:06 PM
PHPRunner Tips and Tricks
fhumanes author

img alt
Those who rent a hosting for our developments, I am in this case, we see that our machines are sometimes in a country and other times in another, and that above all nor the operating system nor the database manager is in the Time Zone that interests me.

Also, it may still be the ability to adjust the server, require different applications have different time zones.

In my concrete case, when residing in Madrid, the Server, both in OS and DB, are at one hour less.

Objective

Configure PHPRunner applications to set an independent time zone from the server time.

DEMO: https://fhumanes.com/change_time/

If you are interested in this topic, you continue reading the article in this link.

fhumanes author 11/18/2021

To adjust on PHPRunner we have to modify the "After Application Initialized" event. The code that has this event is executed in each request and interaction that the user does with the application.

// Poner zona horaria distinta al servidor
$now = date('d-m-Y H:i:s');
$fecha = new DateTime($now, new DateTimeZone('Europe/Madrid'));
$timezone = $fecha->format('P'); // "+01:00" para Madrid
// MYSQL ---------------------------------------------------------------
DB::Exec("SET time_zone = '$timezone'"); //
// PHP ----------------------------------------------------------------
date_default_timezone_set('Europe/Madrid'); // Madrid