The MySQL and Apache servers remain in UTC time.

Solved
cocodu67... Posted messages 3178 Registration date   Status Member Last intervention   -  
cocodu67... Posted messages 3178 Registration date   Status Member Last intervention   -

Hello,

I changed servers while staying with the same host in order to switch management platforms; it's no longer CPanel this time. It's not a VPS, but not a dedicated server either, even though the RAM and CPU are reserved for me.

Previously, on CPanel, the Apache server was set to French time, MySQL too, and PHP as well. Now I've been told that only PHP can be set to the French time zone, which has just been fixed.

So I have two problems:

- I have cron jobs that need to run at a specific time. How do I manage that? I can set them to run at 10 PM and since UTC is 2 hours behind French time, they will run at midnight French time at the change of day, and the problem will be solved. But at the time change, since UTC does not change, we will have not 2 hours of difference, but only 1. I don't know how to make this as straightforward as possible.


- I sometimes use NOW() in my SQL queries. I can change that to use (NOW() + INTERVAL 2 HOUR), but how do I manage this since sometimes it will not be + 2 hours but apparently 1 hour once we return to standard time in winter?

Thank you in advance

1 answer

  1. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   Ambassadeur 1 588
     

    Hello,

    For your second problem, I wouldn't use NOW SQL; instead, I would calculate the moment in PHP and use that calculated moment in the SQL query.

    Another way to do it would be to store UTC moments in the database rather than local time moments. The conversion would happen during user interactions.

    0
    1. cocodu67... Posted messages 3178 Registration date   Status Member Last intervention   145
       

      Hello,

      To make it look cleaner, I always used NOW(), but indeed, PHP makes it very easy to obtain the date and time in the same format as NOW().

      Regarding the cron jobs that need to run at a specific time, I have an idea. If a task is supposed to start on the 1st of the month at 00:01, it can be scheduled to run every hour every day and check in PHP (which will have the French time) when the day is 1 and the hour is 0 and the minute is 1, put all the code in curly braces, and check with an if statement if the moment has come, executing the code inside the if statement only if it's the right day and the right time. That results in a lot of unnecessary executions, but oh well...

      0
      1. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588 > cocodu67... Posted messages 3178 Registration date   Status Member Last intervention  
         

        Regarding cron jobs, I would record in the database the time of the next execution, to protect against time changes and to manage situations where the server is down for a certain period of time.

        0
      2. cocodu67... Posted messages 3178 Registration date   Status Member Last intervention   145 > yg_be Posted messages 23437 Registration date   Status Contributor Last intervention  
         

        Excuse me, but could you explain to me in what situation there might be a problem if the execution time is indicated in the PHP code?

        0
      3. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588 > cocodu67... Posted messages 3178 Registration date   Status Member Last intervention  
         

        At the change of season, when the clocks go back, there is an opportunity to execute a task twice.

        If the server stops for a few hours and restarts, it is probably useful to execute the tasks that should have run during the downtime.

        0
      4. cocodu67... Posted messages 3178 Registration date   Status Member Last intervention   145 > yg_be Posted messages 23437 Registration date   Status Contributor Last intervention  
         

        Oh yes, that's true that if we remove an hour it will execute twice. In my case, it's not a big deal, but in other situations it can definitely cause quite a few problems.

        Indeed, if the server stops for a while and the daily cron hasn't run, there are things that might not work as expected.

        Thank you for your advice.

        0