programing

Symfony2 및 date_default_timezone_get ()-시스템의 시간대 설정에 의존하는 것은 안전하지 않습니다.

nasanasas 2020. 10. 13. 07:54
반응형

Symfony2 및 date_default_timezone_get ()-시스템의 시간대 설정에 의존하는 것은 안전하지 않습니다.


Symfony2 프로젝트가 있습니다. 오늘 내 PHP를 5.5.7로 업데이트했으며 그 이후로

Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in...

내 php.ini에 기본 시간대를 설정했습니다.

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Europe/Paris";

이것이 좋은 php.ini인지 확인하기 위해

phpinfo();

그리고 내가 거기에 도착하는 경로는 내가 수정하는 경로입니다.

 /usr/local/php5.5.7/lib 

그러나 거기에서 나는

Default timezone    UTC 

이상합니다.

어떤 생각? 감사합니다.


Apache의에서 설정하려고 php.ini하지만 CLI (명령 줄 인터페이스) php.ini가 좋지 않습니다.

php.ini다음 명령으로 파일을 찾으십시오 .

php -i | grep php.ini

그런 다음 검색 date.timezone하여 "Europe/Amsterdam". 모든 유효한 시간대는 http://php.net/manual/en/timezones.php 에서 찾을 수 있습니다 .

다른 방법으로 (다른 방법이 작동하지 않는 경우) Symfony 프로젝트 디렉토리 AppKernel.php의 폴더 아래 에있는 파일을 검색 app하십시오 . 클래스에서 아래 함수를 덮어 씁니다 .__constructAppKernel

<?php     

class AppKernel extends Kernel
{
    // Other methods and variables


    // Append this init function below

    public function __construct($environment, $debug)
    {
        date_default_timezone_set( 'Europe/Paris' );
        parent::__construct($environment, $debug);
    }

}

이 문제를 해결하는 비슷한 방법을 찾았습니다 (적어도 저에게는 그랬습니다).

  1. 먼저이 위치를 확인하세요 CLI php.ini.

    php -i | grep "php.ini"

  2. 제 경우에는 다음과 같이 끝났습니다. 구성 파일 (php.ini) 경로 => / etc

  3. 그런 다음 cd ..모든 방법의 뒤로 cd/etc, 할 ls내 경우의 php.ini 파일에 나타나지 않았어요 만 php.ini.default

  4. 이제 php.ini라는 이름의 php.ini.default 파일을 복사합니다.

    sudo cp php.ini.default php.ini

  5. 편집하려면 파일의 권한을 변경하십시오.

    sudo chmod ug+w php.ini

    sudo chgrp staff php.ini

  6. 디렉토리를 열고 php.ini 파일을 편집하십시오.

    open .

    팁 : 일부 권한 문제로 인해 php.ini를 편집 할 수없는 경우 'php.ini.default'를 복사하여 바탕 화면에 붙여넣고 이름을 'php.ini'로 바꾼 다음 단계에 따라 열고 편집하십시오. 7. 그런 다음 / etc 폴더로 이동 (복사 + 붙여 넣기)합니다. 문제가 해결됩니다.

  7. [날짜]를 검색하고 다음 줄이 올바른 형식인지 확인합니다.

    date.timezone = "Europe/Amsterdam"

이것이 당신을 도울 수 있기를 바랍니다.


현재 crack에 의해 허용되는 답변은 Symfony 2.3에서 더 이상 사용되지 않으며 3.0에서 제거됩니다. 생성자로 이동해야합니다.

public function __construct($environment, $debug) {
    date_default_timezone_set('Europe/Warsaw');
    parent::__construct($environment, $debug);
}

PHP 5.5부터 CLI 인터페이스를위한 별도의 php.ini 파일이 있습니다. 명령 줄에서 심포니 콘솔을 사용하는 경우이 특정 php.ini가 사용됩니다.

Ubuntu 13.10에서 파일 확인 :

/etc/php5/cli/php.ini


Redhat 또는 Cent OS에서 PHP 5.1을 사용할 때 문제가 나타납니다.

RHEL / CentOS의 PHP 5.1은 시간대 기능을 지원하지 않습니다.


Following up on sas's answer, PHP 5.4, Symfony 2.8, I had to use

ini_set('date.timezone','<whatever timezone string>');

instead of date_default_timezone_set. I also added a call to ini_set to the top of a custom web/config.php to get that check to succeed.


add this code to Your AppKernel Class:

public function init()
{
    date_default_timezone_set('Asia/Tehran');
    parent::init();
}

참고URL : https://stackoverflow.com/questions/20743060/symfony2-and-date-default-timezone-get-it-is-not-safe-to-rely-on-the-system

반응형