我具有使用马丁·托马Github Link Here
的iCal解析器的功能。此功能的执行速度非常慢,大约需要12秒才能从iCal日历中获取活动日期。
如何改善功能流程?
然后,在页面底部我的Javascript加载中,将exclusions变量输出到结束body标签之前。
我尝试了没有此功能的页面,并且页面加载非常快,因此我将其范围缩小到了此功能。
可能是我不正确地重用了iCal类,但我不知道解决方法。
请帮助
function process_ical($airbnb_ical_link,$google_ical_link,$booking_dot_com_ical_link,$homeaway_ical_link) {
require 'class.iCalReader.php';
$exclusions = '"2019-01-01"';
if ($airbnb_ical_link != '') {
$ical = new ICal($airbnb_ical_link);
$events = $ical->events();
if (is_array($events) || is_object($events)) {
foreach ($events as $event) {
$formatedStart = $ical->iCalDateToUnixTimestamp($event['DTSTART']);
$formatedEnd = $ical->iCalDateToUnixTimestamp($event['DTEND']);
$str1 = date('Y-m-d',$formatedStart);
$str2 = date('Y-m-d',$formatedEnd);
$date_from = strtotime($str1);
$date_to = strtotime($str2);
$date_to = ($date_to - 86400); // Fix the extra day issue
for ($i=$date_from; $i<=$date_to; $i+=86400) {
$exclusions .= date(',"Y-m-d"', $i);
}
}
}
}
if ($google_ical_link != '') {
$ical2 = new ICal($google_ical_link);
$events2 = $ical2->events();
if (is_array($events2) || is_object($events2)) {
foreach ($events2 as $event2) {
$formatedStart2 = $ical2->iCalDateToUnixTimestamp($event2['DTSTART']);
$formatedEnd2 = $ical2->iCalDateToUnixTimestamp($event2['DTEND']);
$strr1 = date('Y-m-d',$formatedStart2);
$strr2 = date('Y-m-d',$formatedEnd2);
$google_date_from = strtotime($strr1);
$google_date_to = strtotime($strr2);
$google_date_to = ($google_date_to - 86400); // Fix the extra day issue
for ($i=$google_date_from; $i<=$google_date_to; $i+=86400) {
$exclusions .= date(',"Y-m-d"', $i);
}
}
}
}
if ($booking_dot_com_ical_link != '') {
$ical3 = new ICal($booking_dot_com_ical_link);
$events3 = $ical3->events();
if (is_array($events3) || is_object($events3)) {
foreach ($events3 as $event3) {
$formatedStart3 = $ical3->iCalDateToUnixTimestamp($event3['DTSTART']);
$formatedEnd3 = $ical3->iCalDateToUnixTimestamp($event3['DTEND']);
$str1_priceline = date('Y-m-d',$formatedStart3);
$str2_priceline = date('Y-m-d',$formatedEnd3);
$priceline_date_from = strtotime($str1_priceline);
$priceline_date_to = strtotime($str2_priceline);
$priceline_date_to = ($priceline_date_to - 86400); // Fix the extra day issue
for ($i=$priceline_date_from; $i<=$priceline_date_to; $i+=86400) {
$exclusions .= date(',"Y-m-d"', $i);
}
}
}
}
if ($homeaway_ical_link != '') {
$ical4 = new ICal($homeaway_ical_link);
$events4 = $ical4->events();
if (is_array($events4) || is_object($events4)) {
foreach ($events4 as $event4) {
$formatedStart4 = $ical4->iCalDateToUnixTimestamp($event4['DTSTART']);
$formatedEnd4 = $ical4->iCalDateToUnixTimestamp($event4['DTEND']);
$str1_homeaway = date('Y-m-d',$formatedStart4);
$str2_homeaway = date('Y-m-d',$formatedEnd4);
$homeaway_date_from = strtotime($str1_homeaway);
$homeaway_date_to = strtotime($str2_homeaway);
$homeaway_date_to = ($homeaway_date_to - 86400); // Fix the extra day issue
for ($i=$homeaway_date_from; $i<=$homeaway_date_to; $i+=86400) {
$exclusions .= date(',"Y-m-d"', $i);
}
}
}
}
return $exclusions;
}