php – 哪一个更快get_headers()vs curl()?
发布时间:2020-12-13 17:48:31 所属栏目:PHP教程 来源:网络整理
导读:我需要编写一个php脚本,它将接受csv文件作为输入,然后解析其中提供的产品URL. 之后,我需要验证哪个产品网址存在,哪个不存在. 我有curl()和get_headers()这两个选项. 那么请你告诉我哪一个更快更可靠? 任何帮助都感激不尽. 解决方法 我用100个独特的域测试了
我需要编写一个php脚本,它将接受csv文件作为输入,然后解析其中提供的产品URL.
之后,我需要验证哪个产品网址存在,哪个不存在. 那么请你告诉我哪一个更快更可靠? 任何帮助都感激不尽. 解决方法
我用100个独特的域测试了这个:
$urls = [ "http://familyshare.com/","http://elitedaily.com/","http://www.pickthebrain.com/","http://i100.independent.co.uk/","http://thingsorganizedneatly.tumblr.com/","http://www.cheatsheet.com/","https://jet.com/","https://nightwalk.withgoogle.com/en/panorama","http://www.vumble.com/","http://fusion.net/","https://www.zozi.com","http://joshworth.com/dev/pixelspace/pixelspace_solarsystem.html","http://how-old.net/","https://www.dosomething.org","https://devart.withgoogle.com/","http://www.ranker.com/","http://the-toast.net/","https://www.futurelearn.com/","https://croaciaaudio.com/","http://www.thesimpledollar.com/","http://giphy.com/giphytv","http://snapzu.com/","https://www.touchofmodern.com/","http://www.howstuffworks.com/","http://www.sporcle.com/","http://www.factcheck.org/","https://www.privacytools.io/","http://tiffanithiessen.com/","http://www.supercook.com/","http://www.livescience.com/","http://www.freshnessmag.com","http://www.abeautifulmess.com/","http://cardboardboxoffice.com/","http://www.takepart.com/","http://www.fixya.com/","http://bestreviews.com/","http://theodysseyonline.com/","http://justdelete.me/","http://adventure.com/","http://www.carryology.com/","http://whattheysee.tumblr.com/","https://unsplash.com/","http://fromwhereidrone.com/","http://www.attn.com/","http://ourworldindata.org/","http://www.melty.com/","http://www.truthdig.com/","https://tosdr.org/","https://thinga.com/","http://forvo.com/","http://tiii.me/","https://snapguide.com/","http://www.tubefilter.com/","http://www.inherentlyfunny.com/","http://www.someecards.com/","https://this.cm/","http://littlebigdetails.com/","http://clapway.com/","http://www.nerdfitness.com/","http://iwantdis.com/","http://Racked.com","http://thesweetsetup.com/","http://www.we-heart.com/","https://www.revealnews.org/","https://featuredcreature.com/","http://www.scotthyoung.com/blog/","http://www.thehandandeye.com/","http://www.thenorthernpost.com/","http://www.welzoo.com/","http://www.tickld.com/","http://thinksimplenow.com/","http://www.quietrev.com/","http://www.freshoffthegrid.com/","https://www.generosity.com/","http://addicted2success.com/","http://cubiclane.com/","http://waitbutwhy.com/","http://toolsandtoys.net/","http://googling.co/","http://penelopetrunk.com/","http://iaf.tv/","http://artofvisuals.com/","http://www.lifeaftercollege.org/blog","http://listverse.com/","http://chrisguillebeau.com/","http://expeditionportal.com/","http://www.marieforleo.com/","http://mostexclusivewebsite.com/","http://www.alphr.com/","http://www.rtings.com/","http://all-that-is-interesting.com/","http://theunbeatnpath.xyz/","http://www.keepinspiring.me/","https://paidtoexist.com/blog/","http://www.lovethispic.com/","http://riskology.co/blog/","http://geyserofawesome.com/","http://www.eugenewei.com/","http://clickotron.com/" ]; $startTime = microtime(true); stream_context_set_default( array( 'http' => array( 'method' => 'HEAD' ) ) ); $headers1 = []; foreach ($urls as $url) { $headers1[] = get_headers($url); } $endTime = microtime(true); $elapsed = $endTime - $startTime; echo "Execution time : $elapsed seconds n"; $startTime = microtime(true); $headers2 = []; foreach ($urls as $url) { $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,true); curl_setopt($ch,CURLOPT_NOBODY,CURLOPT_RETURNTRANSFER,CURLOPT_TIMEOUT,10); $header2[] = curl_exec($ch); } $endTime = microtime(true); $elapsed = $endTime - $startTime; echo "Execution time : $elapsed seconds n"; get_headers(GET)vs cURL:
get_headers(HEAD)vs cURL:
所以cURL确实快得多. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |