doufocheng6233 2017-02-08 17:07
浏览 88
已采纳

PHP和MySQL - 为什么依赖系统时间设置是不安全的?

There are so many places where you can modify the time settings in a set up of Linux, Apache, PHP, and MySQL. I need to set everything to UTC in my server and I wondered why not just set the system time to UTC and all services just need to use the timezone "SYSTEM" as I did for MySQL.

However, a simple PHP warning made me doubt my decision. "It is not safe to reply on the system's timezone settings"

I have to questions, one may lead to another.

  1. Why is it not safe to rely on the system time settings, specifically CentOS, in PHP, Apache, or MySQL?
  2. What is the best way to unify the time settings from all services: Apache, PHP, and MySQL?
  • 写回答

1条回答 默认 最新

  • douzui0143 2017-02-08 17:13
    关注
    1. You should not rely on system settings as they can be changed accidentally, as simple as that. Instead, specifying the desired timezone in php.ini makes sure somebody gave this a thought and selected the correct timezone that is going to be used (unless overridden by ini_set)

    2. The best way is to specify the timezone you want in corresponding ini and conf files.

    Moreover, if you have website now on US server and in few years you migrate to UK server, you want to copy your conf files as well and this assures that same timezone is used at all times.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大