+运算符把右边的数组元素附加到左边的数组后面,两个数组中都有的键名,则只用左边数组中的,右边的被忽略。


+运算符把右边的数组元素附加到左边的数组后面,两个数组中都有的键名,则只用左边数组中的,右边的被忽略。
public static function getIpX(): ?string {
[$ip] = self::getIp();
return $ip;
}
public static function getIp(): array {
$ip0 = $ip = $_SERVER['REMOTE_ADDR'] ?? null;
if (in_array($ip, [
'10.29.185.7', '127.0.0.1', '172.17.0.1', '172.31.242.237', # 可信IP列表
])) {
$ip1 = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? null;
if ($ip1) {
$ip0 = $ip1;
$ip = explode(',', $ip1)[0];
}
}
if (!$ip) {
$ip = $_SERVER['REMOTE_ADDR'] ?? null;
}
return [$ip, $ip0];
}
nginx:
client_max_body_size 1G;
php.ini:
upload_max_filesize = 1G
post_max_size = 1G
$fp = fopen(sprintf("tmp/wk_exam_examination.%d.lock", $userid % 10), "w");
if (!flock($fp, LOCK_EX | LOCK_NB)) {
?>
<style>
#info {
text-align: center;
margin: 50px 0;
}
#info td {
font-size: 36px;
color: seagreen;
}
</style>
<div id='info'></div>
<script>
let sec = 5000
setTimeout(function () {
window.location.reload()
}, sec)
setInterval(function () {
sec -= 100
if (sec >= 0) {
let ok = sec / 1000
document.getElementById('info').innerHTML = `<table style="margin: 0 auto;">
<tr><td style='width: 50%; text-align: right;'>页面排队中...</td>
<td style="width: 2em; text-align: center;">${ok}</td><td>秒后将重试!</td></tr></table>`;
}
}, 100)
</script><?php
die;
}
queue:listen 是热加载,效率低,修改job类后会生效
queue:work 不会热加载,效率高,修改job类后需要重启才能生效
run __construct
run shutdown_function
run __destruct
* unset 等操作可以提前触发 __destruct
可以利用变量作用域在__destruct内来释放连接、解锁等释放操作
opcache.enable_cli + xdebug + swoole 可能会导致“段错误”(Segmentation fault)