简体   繁体   English

完全解析url的最有效方法是什么(使用php和curl)

[英]what is the most efficient way to fully resolve a url (using php and curl)

I'm looking for the most effecient way to resolve a given url to its final end point, following all 30x redirects and location headers. 我正在寻找最有效的方法,将所有30x重定向和位置标头解析为给定url到其最终终点。

Basically, I have a bunch of URLs like http://foo.com that when you go to them, they end up at a page like http://foo.com/Welcome.html and i need to find that last url. 基本上,我有一堆URL,例如http://foo.com ,当您访问它们时,它们最终会出现在http://foo.com/Welcome.html之类的页面上,我需要找到最后一个URL。

right now, i'm using CURLOPT_FOLLOWLOCATION and CURLOPT_NOBODY (since i really dont care about the text returned) and once its exec'd, i run curl_getinfo() and save the 'url' key from that array. 现在,我正在使用CURLOPT_FOLLOWLOCATIONCURLOPT_NOBODY (因为我真的不在乎返回的文本),并且一旦执行,我就运行curl_getinfo()并从该数组中保存'url'键。

i just keep thinking that this is such a huge waste of <something> and there is likely a better way. 我一直认为这是<something>的巨大浪费,并且可能有更好的方法。

EDIT: For those that read this later. 编辑:对于那些稍后阅读。 I did end up finding a better solution (that didnt involve curl), see get_headers() in php5+ 我最终找到了更好的解决方案(不涉及卷曲),请参见php5 +中的get_headers()

You can do this manually in php by analysing received headers, but cURL does exactly the same thing. 您可以通过分析接收到的标头在php中手动完成此操作,但是cURL的作用完全相同。 There are no other direct methods, and cURL is the most comfortable one. 没有其他直接方法,而cURL是最舒适的方法。 Don't care about it. 不在乎。

OR you can use some search engines information, that had been already retrived by crawler. 或者,您可以使用搜寻器已经检索到的一些搜索引擎信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM