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);
?>