Пример #1
0
function setCacheExpiry($entriesCount, $feedId)
{
    $expiryArr = kConf::hasMap("v3cache_getfeed_expiry") ? kConf::getMap("v3cache_getfeed_expiry") : array();
    foreach ($expiryArr as $item) {
        if ($item["key"] == "partnerId" && $item["value"] == kCurrentContext::$partner_id || $item["key"] == "feedId" && $item["value"] == $feedId) {
            KalturaResponseCacher::setExpiry($item["expiry"]);
            return;
        }
    }
    $expiry = kConf::get("v3cache_getfeed_default_cache_time_frame", 'local', 86400);
    if (kConf::hasParam("v3cache_getfeed_short_limits_array")) {
        $shortLimits = kConf::get("v3cache_getfeed_short_limits_array");
    } else {
        $shortLimits = array(50 => 900, 100 => 1800, 200 => 3600, 400 => 7200);
    }
    foreach ($shortLimits as $numOfEntries => $cacheTimeFrame) {
        if ($entriesCount <= $numOfEntries) {
            $expiry = min($expiry, $cacheTimeFrame);
        }
    }
    KalturaResponseCacher::setExpiry($expiry);
}
Пример #2
0
 private function responseHandlingIsLive($isLive)
 {
     if (!$isLive) {
         KalturaResponseCacher::setExpiry(self::ISLIVE_ACTION_CACHE_EXPIRY_WHEN_NOT_LIVE);
         KalturaResponseCacher::setHeadersCacheExpiry(self::ISLIVE_ACTION_CACHE_EXPIRY_WHEN_NOT_LIVE);
     } else {
         KalturaResponseCacher::setExpiry(self::ISLIVE_ACTION_CACHE_EXPIRY_WHEN_LIVE);
         KalturaResponseCacher::setHeadersCacheExpiry(self::ISLIVE_ACTION_CACHE_EXPIRY_WHEN_LIVE);
     }
     return $isLive;
 }
Пример #3
0
 /**
  * Delivering the status of a live stream (on-air/offline) if it is possible
  * 
  * @action isLive
  * @param string $id ID of the live stream
  * @param KalturaPlaybackProtocol $protocol protocol of the stream to test.
  * @return bool
  * 
  * @throws KalturaErrors::LIVE_STREAM_STATUS_CANNOT_BE_DETERMINED
  * @throws KalturaErrors::INVALID_ENTRY_ID
  */
 public function isLiveAction($id, $protocol)
 {
     KalturaResponseCacher::setExpiry(self::ISLIVE_ACTION_CACHE_EXPIRY);
     KalturaResponseCacher::setConditionalCacheExpiry(self::ISLIVE_ACTION_CONDITIONAL_CACHE_EXPIRY);
     if (!kCurrentContext::$ks) {
         kEntitlementUtils::initEntitlementEnforcement(null, false);
         $liveStreamEntry = kCurrentContext::initPartnerByEntryId($id);
         if (!$liveStreamEntry || $liveStreamEntry->getStatus() == entryStatus::DELETED) {
             throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_ID, $id);
         }
         // enforce entitlement
         $this->setPartnerFilters(kCurrentContext::getCurrentPartnerId());
     } else {
         $liveStreamEntry = entryPeer::retrieveByPK($id);
     }
     if (!$liveStreamEntry || $liveStreamEntry->getType() != entryType::LIVE_STREAM) {
         throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_ID, $id);
     }
     /* @var $liveStreamEntry LiveStreamEntry */
     if (in_array($liveStreamEntry->getSource(), array(KalturaSourceType::LIVE_STREAM, KalturaSourceType::LIVE_STREAM_ONTEXTDATA_CAPTIONS))) {
         return $liveStreamEntry->hasMediaServer();
     }
     $dpda = new DeliveryProfileDynamicAttributes();
     $dpda->setEntryId($id);
     $dpda->setFormat($protocol);
     switch ($protocol) {
         case KalturaPlaybackProtocol::HLS:
         case KalturaPlaybackProtocol::APPLE_HTTP:
             $url = $liveStreamEntry->getHlsStreamUrl();
             foreach (array(KalturaPlaybackProtocol::HLS, KalturaPlaybackProtocol::APPLE_HTTP) as $hlsProtocol) {
                 $config = $liveStreamEntry->getLiveStreamConfigurationByProtocol($hlsProtocol, requestUtils::getProtocol());
                 if ($config) {
                     $url = $config->getUrl();
                     $protocol = $hlsProtocol;
                     break;
                 }
             }
             KalturaLog::info('Determining status of live stream URL [' . $url . ']');
             $urlManager = DeliveryProfilePeer::getLiveDeliveryProfileByHostName(parse_url($url, PHP_URL_HOST), $dpda);
             if ($urlManager) {
                 return $urlManager->isLive($url);
             }
             break;
         case KalturaPlaybackProtocol::HDS:
         case KalturaPlaybackProtocol::AKAMAI_HDS:
             $config = $liveStreamEntry->getLiveStreamConfigurationByProtocol($protocol, requestUtils::getProtocol());
             if ($config) {
                 $url = $config->getUrl();
                 KalturaLog::info('Determining status of live stream URL [' . $url . ']');
                 $urlManager = DeliveryProfilePeer::getLiveDeliveryProfileByHostName(parse_url($url, PHP_URL_HOST), $dpda);
                 if ($urlManager) {
                     return $urlManager->isLive($url);
                 }
             }
             break;
     }
     throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_STATUS_CANNOT_BE_DETERMINED, $protocol);
 }
 public function adjustApiCacheForException($ex)
 {
     KalturaResponseCacher::setExpiry(120);
     $cacheConditionally = false;
     if ($ex instanceof KalturaAPIException && kConf::hasParam("v3cache_conditional_cached_errors")) {
         $cacheConditionally = in_array($ex->getCode(), kConf::get("v3cache_conditional_cached_errors"));
     }
     if (!$cacheConditionally) {
         KalturaResponseCacher::disableConditionalCache();
     }
 }
    header('KalturaSyndication: Database error');
    die;
} catch (Exception $ex) {
    KalturaLog::err($ex->getMessage());
    header('KalturaSyndication: ' . str_replace(array("\n", "\r"), array("\t", ''), $ex->getMessage()));
    die;
}
$syndicationFeedDB = syndicationFeedPeer::retrieveByPK($feedId);
if (!$syndicationFeedDB) {
    header('KalturaSyndication: Feed Id not found');
    die;
}
// small feeds will have a short
if ($limit) {
    $short_limit = kConf::hasParam("v3cache_getfeed_short_limit") ? kConf::get("v3cache_getfeed_short_limit") : 50;
    if ($limit < $short_limit) {
        KalturaResponseCacher::setExpiry(kConf::hasParam("v3cache_getfeed_short_expiry") ? kConf::get("v3cache_getfeed_short_expiry") : 900);
    }
}
$partnerId = $syndicationFeedDB->getPartnerId();
$expiryArr = kConf::hasMap("v3cache_getfeed_expiry") ? kConf::getMap("v3cache_getfeed_expiry") : array();
foreach ($expiryArr as $item) {
    if ($item["key"] == "partnerId" && $item["value"] == $partnerId || $item["key"] == "feedId" && $item["value"] == $feedId) {
        KalturaResponseCacher::setExpiry($item["expiry"]);
        break;
    }
}
$end = microtime(true);
KalturaLog::info("syndicationFeedRenderer-end [" . ($end - $start) . "]");
KalturaLog::debug("<------------------------------------- syndicationFeedRenderer -------------------------------------");
$cache->end();