唉 通宵上项目发现一个图片检测方法在本地很快 上到服务器上检测卡死。
<?php $img_exists = get_headers($pic,1); if(!empty($img_exists) && $img_exists[0] =='HTTP/1.1 200 OK' && $img_exists['Content-Length']!=18771){ $model_show .= '<img src="'.$pic.'" width="438" />'; } ?>
很奇怪上到服务器上就很慢。 本来系统用的是file_get_contents 改良了下换成get_header上线后又慢
baidu了一下 curl_要比 get_header()快很多。试了一下果然不错。
<?php $ch = curl_init(); // 启动一个CURL会话 curl_setopt($ch,CURLOPT_HEADER,1); //不示返回的Header区域内容 curl_setopt($ch, CURLOPT_NOBODY, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch,CURLOPT_URL,$pic); $hd = curl_exec($ch); if(!empty($hd) && !strpos($hd,'Content-Length: 18771')){ $model_show .= '<img src="'.$pic.'" width="438" />'; } ?>
同事推荐个 getImageSize效率也不错。不过有局限性 有时间的同学可以试下