Skip to main content

PHP FAQ

Timezone

  • 默认使用 TZ 环境变量
<?php
date_default_timezone_set('Asia/Shanghai');

$script_tz = date_default_timezone_get();
if (strcmp($script_tz, ini_get('date.timezone'))){
echo '时区与INI配置 不同';
} else {
echo '时区与INI配置 相同'
}

php.ini

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
; https://www.php.net/manual/en/timezones.asia.php
date.timezone = "Asia/Shanghai"

redis session

/etc/php5/fpm/php.ini

session.save_handler = redis
# key 格式
# PHPREDIS_SESSION:j9rsgtde6st2rqb6lu5u6f4h83
session.save_path = "tcp://10.10.1.1:6379?auth=yourverycomplexpasswordhere"

强制类型

<?
declare(strict_types=1)

Connection to `ssl://pecl.php.net:443' failed: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP

apk add php7-openssl

sodium_crypto_aead_aes256gcm_decrypt

apk add php7-sodium
  • sodium_crypto_aead_aes256gcm_is_available()

Allowed memory size of 134217728 bytes exhausted (tried to allocate 65011744 bytes)

  • php.ini
    • memory_limit=128M
<?
ini_set('memory_limit', '-1');

epoll_wait() reported that client prematurely closed connection, so upstream connection is closed too while sending request to upstream

Declaration of Monolog\Logger must be compatible with PsrExt\Log\LoggerInterface

apk del php82-pecl-psr