I'm using urlresolver in a piece of code that retrieves general info from a URL to provide a preview. I loop through all the domains in a string and use urlresolver on each domain before processing it. The problem is that the first domain keeps failing even if the next domain is exactly the same. The next instances of the domain will resolve fine.
To make it a bit clearer:
Domain list:
- www.github.com
- www.github.com
- www.github.com
Results:
- Connection failed
- Success!
- Success!
You can run my test here (sorry for the adult domain):
https://namethatpornstar.com/test-urlresolver.php?id=3028462
And here is the quick function I'm using on that link to show the issue.
if(!function_exists('testResolver')){
function testResolver($string) {
$resolver = new mattwright\URLResolver();
$resolver->setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36');
$resolver->setCookieJar('/tmp/url_resolver.cookies');
$resolver->setRequestTimeout(10);
$regex = '/https?\:\/\/[^\" \n]+/i';
preg_match_all($regex, $string, $urlarray);
$urlarray[0] = array_unique($urlarray[0]);
$urls = array();
print_r("<pre>");
print_r($urlarray);
foreach ($urlarray[0] as &$url) {
$url_result = $resolver->resolveURL($url);
if($url_result->didConnectionFail()) {
echo "Connection failed" . "<br>";
}
if ($url_result->didErrorOccur()) {
echo $url_result->getErrorMessageString();
} else {
echo "Success!" . "<br>";
}
}
}
}
I guess it must be something simple I'm overlooking because it only fails this way on some domains.
Any ideas?
I'm using urlresolver in a piece of code that retrieves general info from a URL to provide a preview. I loop through all the domains in a string and use urlresolver on each domain before processing it. The problem is that the first domain keeps failing even if the next domain is exactly the same. The next instances of the domain will resolve fine.
To make it a bit clearer:
Domain list:
Results:
You can run my test here (sorry for the adult domain):
https://namethatpornstar.com/test-urlresolver.php?id=3028462
And here is the quick function I'm using on that link to show the issue.
I guess it must be something simple I'm overlooking because it only fails this way on some domains.
Any ideas?