date_default_timezone_set('PRC');
/**
* 求取从某日起经过一定天数后的日期,
* 排除周六周日和节假日
* @param $start 开始日期
* @param $offset 经过天数
* @param $exception 例外的节假日
* @param $allow 允许的日期(预留参数)
* @return
* examples:输入(2010-06-25,5,''),得到2010-07-02
*/
function getEndDay( $start='now', $offset=0, $exception='', $allow='' ){
//先计算不排除周六周日及节假日的结果
$starttime = strtotime($start);
$endtime = $starttime + $offset * 24 * 3600;
$end = date('Y-m-d', $endtime);
//然后计算周六周日引起的偏移
$weekday = date('N', $starttime);//得到星期值:1-7
$remain = $offset % 7;
$newoffset = 2 * ($offset - $remain) / 7;//每一周需重新计算两天
if( $remain > 0 ){//周余凑整
$tmp = $weekday + $remain;
if( $tmp >= 7 ){
$newoffset += 2;
}else if( $tmp == 6 ){
$newoffset += 1;
}
//考虑当前为周六周日的情况
if( $weekday == 6 ){
$newoffset -= 1;
}else if( $weekday == 7 ){
$newoffset -= 2;
}
}
//再计算节假日引起的偏移
if( is_array($exception) ){//多个节假日
foreach ($exception as $day){
$tmp_time = strtotime($day);
if( $tmp_time>$starttime && $tmp_time<=$endtime ){//在范围(a,b]内
$weekday_t = date('N', $tmp_time);
if($weekday_t <= 5){//防止节假日与周末重复
$newoffset += 1;
}
}
}
}else{//单个节假日
if( $exception!='' ){
$tmp_time = strtotime($exception);
if( $tmp_time>$starttime && $tmp_time<=$endtime ){
$weekday_t = date('N', $tmp_time);
if($weekday_t <= 5){
$newoffset += 1;
}
}
}
}
//根据偏移天数,递归做等价运算
if($newoffset > 0){
#echo "[{$start} -> {$offset}] = [{$end} -> {$newoffset}]"."
\n";
return getEndDay($end,$newoffset,$exception,$allow);
}else{
return $end;
}
}
/**
* 暴力循环方法
*/
function getEndDay2( $start='now', $offset=0, $exception='', $allow='' ){
$starttime = strtotime($start);
$tmptime = $starttime + 24*3600;
while( $offset > 0 ){
$weekday = date('N', $tmptime);
$tmpday = date('Y-m-d', $tmptime);
$bfd = false;//是否节假日
if(is_array($exception)){
$bfd = in_array($tmpday,$exception);
}else{
$bfd = ($exception==$tmpday);
}
if( $weekday<=5 && !$bfd){//不是周末和节假日
$offset--;
#echo "tmpday={$tmpday}"."
";
}
$tmptime += 24*3600;
}
return $tmpday;
}
$exception = array(
'2010-01-01','2010-01-02','2010-01-03',
'2010-04-03','2010-04-04','2010-04-05',
'2010-05-01','2010-05-02','2010-05-03',
'2010-06-14','2010-06-15','2010-06-16',
'2010-09-22','2010-09-23','2010-09-24',
'2010-10-01','2010-10-02','2010-10-03','2010-10-04',
'2010-10-05','2010-10-06','2010-10-07',
);
//echo getEndDay('2010-08-27',3,'');
//echo getEndDay('2010-06-25',15,'2010-07-07');
$t1 = microtime();
echo getEndDay('2010-05-12',66,$exception)."
";
$t2 = microtime();echo "use ".($t2-$t1)." s
";
echo getEndDay2('2010-05-12',66,$exception)."
";
$t3 = microtime();echo "use ".($t3-$t2)." s
";

负载均衡会影响会话管理,但可以通过会话复制、会话粘性和集中式会话存储解决。1.会话复制在服务器间复制会话数据。2.会话粘性将用户请求定向到同一服务器。3.集中式会话存储使用独立服务器如Redis存储会话数据,确保数据共享。

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

PHP会话的替代方案包括Cookies、Token-basedAuthentication、Database-basedSessions和Redis/Memcached。1.Cookies通过在客户端存储数据来管理会话,简单但安全性低。2.Token-basedAuthentication使用令牌验证用户,安全性高但需额外逻辑。3.Database-basedSessions将数据存储在数据库中,扩展性好但可能影响性能。4.Redis/Memcached使用分布式缓存提高性能和扩展性,但需额外配

Sessionhijacking是指攻击者通过获取用户的sessionID来冒充用户。防范方法包括:1)使用HTTPS加密通信;2)验证sessionID的来源;3)使用安全的sessionID生成算法;4)定期更新sessionID。

本文比较了PHP和ASP.NET,重点是它们对大规模Web应用程序,性能差异和安全功能的适用性。两者对于大型项目都是可行的,但是PHP是开源和无关的,而ASP.NET,


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3汉化版
中文版,非常好用

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具