PHP cURL connection timeout in different port

606 Views Asked by At

I'm trying to read shoutcast stream status using curl. the port of stream status normally different from 80. So i'm using CURLOPT_PORT as others answer on this topic .But still getting timed out error.

My code:

 $link=trim($_GET['link']);
 preg_match ( '#^http://(.*):(.*)/|;#' , $link,  $matches);
 $ip=$matches[1];
 $port=$matches[2];

 $ch = curl_init();  
 $agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)';

 curl_setopt ($ch, CURLOPT_URL, $link);
 curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 100);
 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
 curl_setopt ($ch, CURLOPT_HEADER, 0);
 curl_setopt ($ch, CURLOPT_USERAGENT, $agent);
 curl_setopt ($ch, CURLOPT_PORT, $port);

 $contents = curl_exec($ch);

example link: http://206.190.136.212:9402/ error: Failed to connect to 206.190.136.212 port 9402: Connection timed out

0

There are 0 best solutions below