本文整理汇总了PHP中requestUtils::sendCdnHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP requestUtils::sendCdnHeaders方法的具体用法?PHP requestUtils::sendCdnHeaders怎么用?PHP requestUtils::sendCdnHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requestUtils
的用法示例。
在下文中一共展示了requestUtils::sendCdnHeaders方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: list
<?php
list($range_from, $range_to, $range_length) = requestUtils::handleRangeRequest($total_length);
if ($total_length < 1000) {
// (actually $total_length is probably 13 or 143 - header + empty metadata tag) probably a bad flv maybe only the header - dont cache
requestUtils::sendCdnHeaders("flv", $range_length, 0);
} else {
requestUtils::sendCdnHeaders("flv", $range_length);
}
header('Content-Disposition: attachment; filename="video.flv"');
if ($flv_wrapper == null) {
die;
}
$chunk_size = 1 * 1024 * 1024;
$uri = $_SERVER["REQUEST_URI"];
$startTime = microtime(true);
KalturaLog::info("flvclipperSuccess: start dump range:{$range_length}, total:{$total_length}, {$startTime}, {$chunk_size}, {$from_byte}, {$to_byte}, {$audio_only}, {$dump_from_byte}, {$range_from}, {$range_to}, {$cuepoint_time}, {$cuepoint_pos}, {$uri}");
$flv_wrapper->dump($chunk_size, $from_byte, $to_byte, $audio_only, $dump_from_byte, $range_from, $range_to, $cuepoint_time, $cuepoint_pos);
$endTime = microtime(true);
$diffTime = $endTime - $startTime;
KalturaLog::info("flvclipperSuccess: end dump range:{$range_length}, total:{$total_length}, {$diffTime}, {$endTime}, {$chunk_size}, {$from_byte}, {$to_byte}, {$audio_only}, {$dump_from_byte}, {$range_from}, {$range_to}, {$cuepoint_time}, {$cuepoint_pos}, {$uri}");
die;
// prevent symfony from sending its headers and filling our logs with warnings
示例2: execute
public function execute()
{
requestUtils::handleConditionalGet();
$flavorId = $this->getRequestParameter("flavorId");
$shouldProxy = $this->getRequestParameter("forceproxy", false);
$ks = $this->getRequestParameter("ks");
$fileParam = $this->getRequestParameter("file");
$referrer = base64_decode($this->getRequestParameter("referrer"));
if (!is_string($referrer)) {
// base64_decode can return binary data
$referrer = '';
}
$flavorAsset = flavorAssetPeer::retrieveById($flavorId);
if (is_null($flavorAsset)) {
KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
}
$entry = entryPeer::retrieveByPK($flavorAsset->getEntryId());
if (is_null($entry)) {
KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
}
myPartnerUtils::blockInactivePartner($flavorAsset->getPartnerId());
myPartnerUtils::enforceDelivery($flavorAsset->getPartnerId());
//disabled enforce cdn because of rtmp delivery
//requestUtils::enforceCdnDelivery($flavorAsset->getPartnerId());
$syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
if (!kFileSyncUtils::file_exists($syncKey, false)) {
list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
if (is_null($fileSync)) {
KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]");
KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
}
// always dump remote urls so they will be cached by the cdn transparently
$remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
kFile::dumpUrl($remoteUrl, true, true);
}
$path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey);
$flvWrapper = new myFlvHandler($path);
$isFlv = $flvWrapper->isFlv();
$clipFrom = $this->getRequestParameter("clipFrom", 0);
// milliseconds
$clipTo = $this->getRequestParameter("clipTo", 2147483647);
// milliseconds
if ($clipTo == 0) {
$clipTo = 2147483647;
}
if (is_dir($path) && $fileParam) {
$path .= "/{$fileParam}";
//echo "path($path),file($fileParam)";
kFile::dumpFile($path, null, null);
die;
} else {
if (!$isFlv) {
$limit_file_size = 0;
if ($clipTo != 2147483647) {
$mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) {
$duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration());
$limit_file_size = floor(@filesize($path) * ($clipTo / $duration));
}
}
kFile::dumpFile($path, null, null, $limit_file_size);
die;
}
}
$audioOnly = $this->getRequestParameter("audioOnly");
// milliseconds
if ($audioOnly === '0') {
// audioOnly was explicitly set to 0 - don't attempt to make further automatic investigations
} elseif ($flvWrapper->getFirstVideoTimestamp() < 0) {
$audioOnly = true;
}
$seekFrom = $this->getRequestParameter("seekFrom", -1);
if ($seekFrom <= 0) {
$seekFrom = -1;
}
$seekFromBytes = $this->getRequestParameter("seekFromBytes", -1);
if ($seekFromBytes <= 0) {
$seekFromBytes = -1;
}
$bytes = 0;
if ($seekFrom !== -1 && $seekFrom !== 0) {
list($bytes, $duration, $firstTagByte, $toByte) = $flvWrapper->clip(0, -1, $audioOnly);
list($bytes, $duration, $fromByte, $toByte, $seekFromTimestamp) = $flvWrapper->clip($seekFrom, -1, $audioOnly);
$seekFromBytes = myFlvHandler::FLV_HEADER_SIZE + $flvWrapper->getMetadataSize($audioOnly) + $fromByte - $firstTagByte;
} else {
list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly);
}
$metadataSize = $flvWrapper->getMetadataSize($audioOnly);
$dataOffset = $metadataSize + myFlvHandler::getHeaderSize();
$totalLength = $dataOffset + $bytes;
list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly);
list($rangeFrom, $rangeTo, $rangeLength) = requestUtils::handleRangeRequest($totalLength);
if ($totalLength < 1000) {
// (actually $total_length is probably 13 or 143 - header + empty metadata tag) probably a bad flv maybe only the header - dont cache
requestUtils::sendCdnHeaders("flv", $rangeLength, 0);
} else {
requestUtils::sendCdnHeaders("flv", $rangeLength);
}
header('Content-Disposition: attachment; filename="video.flv"');
// dont inject cuepoint into the stream
//.........这里部分代码省略.........
示例3: execute
//.........这里部分代码省略.........
// milliseconds
if (is_null($clipTo)) {
$clipTo = $this->getRequestParameter("clipTo", self::NO_CLIP_TO);
}
// milliseconds
if ($clipTo == 0) {
$clipTo = self::NO_CLIP_TO;
}
if (!is_numeric($clipTo) || $clipTo < 0) {
KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'clipTo must be a positive number');
}
$seekFrom = $this->getRequestParameter("seekFrom", -1);
if ($seekFrom <= 0) {
$seekFrom = -1;
}
$seekFromBytes = $this->getRequestParameter("seekFromBytes", -1);
if ($seekFromBytes <= 0) {
$seekFromBytes = -1;
}
if ($fileParam && is_dir($path)) {
$path .= "/{$fileParam}";
kFileUtils::dumpFile($path, null, null);
KExternalErrors::dieGracefully();
} else {
if (!$isFlv || $clipTo == self::NO_CLIP_TO && $seekFrom < 0 && $seekFromBytes < 0) {
$limit_file_size = 0;
if ($clipTo != self::NO_CLIP_TO) {
if (strtolower($flavorAsset->getFileExt()) == 'mp4' && PermissionPeer::isValidForPartner(PermissionName::FEATURE_ACCURATE_SERVE_CLIPPING, $flavorAsset->getPartnerId())) {
$contentPath = myContentStorage::getFSContentRootPath();
$tempClipName = $version . '_' . $clipTo . '.mp4';
$tempClipPath = $contentPath . myContentStorage::getGeneralEntityPath("entry/tempclip", $flavorAsset->getIntId(), $flavorAsset->getId(), $tempClipName);
if (!file_exists($tempClipPath)) {
kFile::fullMkdir($tempClipPath);
$clipToSec = round($clipTo / 1000, 3);
$cmdLine = kConf::get("bin_path_ffmpeg") . " -i {$path} -vcodec copy -acodec copy -f mp4 -t {$clipToSec} -y {$tempClipPath} 2>&1";
KalturaLog::log("Executing {$cmdLine}");
$output = array();
$return_value = "";
exec($cmdLine, $output, $return_value);
KalturaLog::log("ffmpeg returned {$return_value}, output:" . implode("\n", $output));
}
if (file_exists($tempClipPath)) {
KalturaLog::log("Dumping {$tempClipPath}");
kFileUtils::dumpFile($tempClipPath);
} else {
KalturaLog::err('Failed to clip the file using ffmpeg, falling back to rough clipping');
}
}
$mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) {
$duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration());
$limit_file_size = floor(@kFile::fileSize($path) * ($clipTo / $duration) * 1.2);
}
}
$renderer = kFileUtils::getDumpFileRenderer($path, null, null, $limit_file_size);
if (!$fileName) {
$this->storeCache($renderer, $flavorAsset->getPartnerId());
}
$renderer->output();
KExternalErrors::dieGracefully();
}
}
$audioOnly = $this->getRequestParameter("audioOnly");
// milliseconds
if ($audioOnly === '0') {
// audioOnly was explicitly set to 0 - don't attempt to make further automatic investigations
} elseif ($flvWrapper->getFirstVideoTimestamp() < 0) {
$audioOnly = true;
}
$bytes = 0;
if ($seekFrom !== -1 && $seekFrom !== 0) {
list($bytes, $duration, $firstTagByte, $toByte) = $flvWrapper->clip(0, -1, $audioOnly);
list($bytes, $duration, $fromByte, $toByte, $seekFromTimestamp) = $flvWrapper->clip($seekFrom, -1, $audioOnly);
$seekFromBytes = myFlvHandler::FLV_HEADER_SIZE + $flvWrapper->getMetadataSize($audioOnly) + $fromByte - $firstTagByte;
} else {
list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly);
}
$metadataSize = $flvWrapper->getMetadataSize($audioOnly);
$dataOffset = $metadataSize + myFlvHandler::getHeaderSize();
$totalLength = $dataOffset + $bytes;
list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly);
list($rangeFrom, $rangeTo, $rangeLength) = requestUtils::handleRangeRequest($totalLength);
if ($totalLength < 1000) {
// (actually $total_length is probably 13 or 143 - header + empty metadata tag) probably a bad flv maybe only the header - dont cache
requestUtils::sendCdnHeaders("flv", $rangeLength, 0);
} else {
requestUtils::sendCdnHeaders("flv", $rangeLength);
}
// dont inject cuepoint into the stream
$cuepointTime = 0;
$cuepointPos = 0;
try {
Propel::close();
} catch (Exception $e) {
$this->logMessage("serveFlavor: error closing db {$e}");
}
header("Content-Type: video/x-flv");
$flvWrapper->dump(self::CHUNK_SIZE, $fromByte, $toByte, $audioOnly, $seekFromBytes, $rangeFrom, $rangeTo, $cuepointTime, $cuepointPos);
KExternalErrors::dieGracefully();
}
示例4: execute
//.........这里部分代码省略.........
$ll_url = requestUtils::getCdnHost() . "/s{$request}" . $flv_extension;
$secret = kConf::get("limelight_madiavault_password");
$expire = "&e=" . (time() + 120);
$ll_url .= $expire;
$fs = $seek_from_bytes == -1 ? "" : "&fs={$seek_from_bytes}";
$ll_url .= "&h=" . md5("{$secret}{$ll_url}") . $fs;
//header("Location: $ll_url");
$this->redirect($ll_url);
} else {
if ($cdn_name == "level3") {
$level3_url = $request . $flv_extension;
if ($entry->getSecurityPolicy()) {
$level3_url = "/s{$level3_url}";
// set expire time in GMT hence the date("Z") offset
$expire = "&nva=" . strftime("%Y%m%d%H%M%S", time() - date("Z") + 30);
$level3_url .= $expire;
$secret = kConf::get("level3_authentication_key");
$hash = "0" . substr(self::hmac('sha1', $secret, $level3_url), 0, 20);
$level3_url .= "&h={$hash}";
}
$level3_url .= $seek_from_bytes == -1 ? "" : "&start={$seek_from_bytes}";
header("Location: {$level3_url}");
die;
} else {
if ($cdn_name == "akamai") {
$akamai_url = $request . $flv_extension;
// if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from
if ($seek_from_timestamp == -1) {
$seek_from_timestamp = $seek_from;
}
$akamai_url .= $seek_from_bytes == -1 ? "" : "&aktimeoffset=" . floor($seek_from_timestamp / 1000);
header("Location: {$akamai_url}");
die;
}
}
}
// a seek request without a supporting cdn - we need to send the answer from our server
if ($seek_from_bytes !== -1 && $via_header === null) {
$this->dump_from_byte = $seek_from_bytes;
}
}
}
// always add the file suffix to the request (needed for scrubbing by some cdns,
// and also breaks without extension on some corporate antivirus).
// we add the the novar paramter since a leaving a trailing "?" will be trimmed
// and then the /seek_from request will result in another url which level3
// will try to refetch from the origin
// note that for streamer we dont add the file extension
if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) {
// a seek request without a supporting cdn - we need to send the answer from our server
if ($seek_from_bytes !== -1 && $via_header === null) {
$request .= "/seek_from_bytes/{$seek_from_bytes}";
}
requestUtils::sendCdnHeaders("flv", 0);
header("Location: {$request}" . $flv_extension);
die;
}
// mp4
if (!$isFlv) {
kFile::dumpFile($path);
}
$this->logMessage("flvclipperAction: serving file [{$path}] entry_id [{$entry_id}] clip_from [{$clip_from}] clip_to [{$clip_to}]", "warning");
if ($audio_only === '0') {
// audio_only was explicitly set to 0 - don't attempt to make further automatic investigations
} elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) {
$audio_only = true;
}
//$start = microtime(true);
list($bytes, $duration, $from_byte, $to_byte, $from_ts, $cuepoint_pos) = myFlvStaticHandler::clip($path, $clip_from, $clip_to, $audio_only);
$metadata_size = $flv_wrapper->getMetadataSize($audio_only);
$this->from_byte = $from_byte;
$this->to_byte = $to_byte;
//$end1 = microtime(true);
//$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" );
//$this->logMessage( "flvclipperAction: serving file [$path] t1 [" . ( $end1-$start) . "]");
$data_offset = $metadata_size + myFlvHandler::getHeaderSize();
// if we're returning a partial file adjust the total size:
// substract the metadata and bytes which are not delivered
if ($this->dump_from_byte >= $data_offset && !$audio_only) {
$bytes -= $metadata_size + max(0, $this->dump_from_byte - $data_offset);
}
$this->total_length = $data_offset + $bytes;
//echo " $bytes , $duration ,$from_byte , $to_byte, $cuepoint_pos\n"; die;
$this->cuepoint_time = 0;
$this->cuepoint_pos = 0;
if ($streamer == "chunked" && $clip_to != 2147483647) {
$this->cuepoint_time = $clip_to - 1;
$this->cuepoint_pos = $cuepoint_pos;
$this->total_length += myFlvHandler::CUEPOINT_TAG_SIZE;
}
//$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes with header & md [" . $this->total_length . "] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" );
$this->flv_wrapper = $flv_wrapper;
$this->audio_only = $audio_only;
try {
Propel::close();
} catch (Exception $e) {
$this->logMessage("flvclipperAction: error closing db {$e}");
}
return sfView::SUCCESS;
}
示例5: execute
/**
* Will forward to the regular swf player according to the widget_id
*/
public function execute()
{
$uv_cookie = @$_COOKIE['uv'];
if (strlen($uv_cookie) != 35) {
$uv_cookie = "uv_" . md5(uniqid(rand(), true));
}
setrawcookie('uv', $uv_cookie, time() + 3600 * 24 * 365, '/');
// check if this is a request for the kdp without a wrapper
// in case of an application loading the kdp (e.g. kmc)
$nowrapper = $this->getRequestParameter("nowrapper", false);
// allow caching if either the cache start time (cache_st) parameter
// wasn't specified or if it is past the specified time
$cache_st = $this->getRequestParameter("cache_st");
$allowCache = !$cache_st || $cache_st < time();
$referer = @$_SERVER['HTTP_REFERER'];
$externalInterfaceDisabled = strstr($referer, "bebo.com") === false && strstr($referer, "myspace.com") === false && strstr($referer, "current.com") === false && strstr($referer, "myyearbook.com") === false && strstr($referer, "facebook.com") === false && strstr($referer, "friendster.com") === false ? "" : "&externalInterfaceDisabled=1";
// if there is no wrapper the loader is responsible for setting extra params to the kdp
$noncached_params = "";
if (!$nowrapper) {
$noncached_params = $externalInterfaceDisabled . "&referer=" . urlencode($referer);
}
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? "https" : "http";
$requestKey = $protocol . $_SERVER["REQUEST_URI"];
// check if we cached the redirect url
$cache = new myCache("kwidget", 10 * 60);
// 10 minutes
$cachedResponse = $cache->get($requestKey);
if ($allowCache && $cachedResponse) {
header("X-Kaltura:cached-action");
header("Expires: Sun, 19 Nov 2000 08:52:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Location:{$cachedResponse}" . $noncached_params);
die;
}
// check if we cached the patched swf with flashvars
$cache_swfdata = new myCache("kwidgetswf", 10 * 60);
// 10 minutes
$cachedResponse = $cache_swfdata->get($requestKey);
if ($allowCache && $cachedResponse) {
header("X-Kaltura:cached-action");
requestUtils::sendCdnHeaders("swf", strlen($cachedResponse), 60 * 10);
echo $cachedResponse;
die;
}
$widget_id = $this->getRequestParameter("wid");
$show_version = $this->getRequestParameter("v");
$debug_kdp = $this->getRequestParameter("debug_kdp", false);
$widget = widgetPeer::retrieveByPK($widget_id);
if (!$widget) {
die;
}
// because of the routing rule - the entry_id & kmedia_type WILL exist. be sure to ignore them if smaller than 0
$kshow_id = $widget->getKshowId();
$entry_id = $widget->getEntryId();
$gallery_widget = !$kshow_id && !$entry_id;
if (!$entry_id) {
$entry_id = -1;
}
if ($widget->getSecurityType() != widget::WIDGET_SECURITY_TYPE_TIMEHASH) {
// try eid - if failed entry_id
$eid = $this->getRequestParameter("eid", $this->getRequestParameter("entry_id"));
// try kid - if failed kshow_id
$kid = $this->getRequestParameter("kid", $this->getRequestParameter("kshow_id"));
if ($eid != null) {
$entry_id = $eid;
} elseif ($kid != null) {
$kshow_id = $kid;
}
}
if ($widget->getSecurityType() == widget::WIDGET_SECURITY_TYPE_MATCH_IP) {
$allowCache = false;
// here we'll attemp to match the ip of the request with that from the customData of the widget
$custom_data = $widget->getCustomData();
$valid_country = false;
if ($custom_data) {
// in this case the custom_data should be of format:
// valid_county_1,valid_country_2,...,valid_country_n;falback_entry_id
$arr = explode(";", $custom_data);
$countries_str = $arr[0];
$fallback_entry_id = isset($arr[1]) ? $arr[1] : null;
$fallback_kshow_id = isset($arr[2]) ? $arr[2] : null;
$current_country = "";
$valid_country = requestUtils::matchIpCountry($countries_str, $current_country);
if (!$valid_country) {
KalturaLog::log("kwidgetAction: Attempting to access widget [{$widget_id}] and entry [{$entry_id}] from country [{$current_country}]. Retrning entry_id: [{$fallback_entry_id}] kshow_id [{$fallback_kshow_id}]");
$entry_id = $fallback_entry_id;
$kshow_id = $fallback_kshow_id;
}
}
} elseif ($widget->getSecurityType() == widget::WIDGET_SECURITY_TYPE_FORCE_KS) {
}
$kmedia_type = -1;
// support either uiconf_id or ui_conf_id
$uiconf_id = $this->getRequestParameter("uiconf_id");
if (!$uiconf_id) {
$uiconf_id = $this->getRequestParameter("ui_conf_id");
//.........这里部分代码省略.........
示例6:
<?php
if ($flv_streamer->pendingEntriesCount()) {
requestUtils::sendCdnHeaders("flv", $total_length, 0);
} else {
requestUtils::sendCdnHeaders("flv", $total_length);
}
echo myFlvHandler::createFlvHeader();
$flv_streamer->printMetadata();
$flv_streamer->streamFlv();
die;
// prevent symfony from sending its headers and filling our logs with warnings