php做cdn加速的案例:
在對應的php文件中添加以下代碼:
function sendURL($push_url_data,$url = 'http://push.dnion.com/cdnUrlPush.do')
{
$ch = curl_init(); //初始化curl
curl_setopt($ch, CURLOPT_URL, $url);//設置鏈接
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//設置是否返回信息
curl_setopt($ch, CURLOPT_HEADER, 0);//設置HTTP頭
curl_setopt($ch, CURLOPT_POST, 1);//設置為POST方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $push_url_data);//POST數據
$response = curl_exec($ch);//接收返回信息
if(curl_errno($ch)){//出錯則顯示錯誤信息
print curl_error($ch);
}
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch); //關閉curl鏈接
switch ($httpCode)
{
case 200:
$response_message = "推送成功";
break;
case 999:
$response_message = "用戶名和密碼驗證出錯";
break;
case 997:
$response_message = "域名不合法,不在DNION做加速業務";
break;
case 996:
$response_message = "請求參數獲取失敗,參數為空等";
break;
case 998:
$response_message = "推送的次數過于頻繁,請稍等一分鐘后在推送";
break;
case 500:
$response_message = "服務端程序異常,無法處理請求,請重試";
break;
default:
$response_message = "其他未知輸入,請聯系管理員";
break;
}
echo "時間:".date("Y-m-d H:i:s",time())." 狀態: ".$response_message;
//echo "time:".date("Y-m-d H:i:s",time()).$response;//顯示返回信息
}
$url = "http://網址/index.html";//多網址以半角,割開
$push_data = 'captcha=驗證碼后臺獲取&type=1&url='.$url;
sendURL($push_data);
?>