CURL url link checken mms en shoutcast

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Ceasar Feijen

Ceasar Feijen

07/07/2008 22:10:00
Quote Anchor link
Ik heb een functie om te checken of een link bestaat.

Nu gaat dat in twee gevallen fout nl. bij de volgende type url's
http://shoutcast.omroep.nl:8058
mms://wm1.streaming.castor.nl/100pctnl=wm2
Bij de print_r($matches); laat hij niets zien

Heeft dus te maken met aan het eind een poort en aan het begin mms

Als ik deze twee type url's check op deze website http://www.rexswain.com/httpview.html krijg ik keurig een 200 terug

Heeft iemand misschien een oplossing hiervoor

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?
if( function_exists( 'curl_init' ) ) {
function
check_url($url){
  $parts=parse_url($url);
  if(!$parts) return false; /* the URL was seriously wrong */

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);

  /* set the user agent - might help, doesn't hurt */
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

  /* timeout after the specified number of seconds. assuming that this script runs
    on a server, 20 seconds should be plenty of time to verify a valid URL.  */

  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
  curl_setopt($ch, CURLOPT_TIMEOUT, 20);

  /* don't download the page, just the header (much faster in this case) */
  curl_setopt($ch, CURLOPT_HEADER, true);
  curl_setopt($ch, CURLOPT_NOBODY, true);


  /* handle HTTPS links */
  if($parts['scheme']=='https'){
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  }


  $response = curl_exec($ch);
  curl_close($ch);

  /*  get the status code from HTTP headers */
  if(preg_match("/HTTP\/1\.[1|0]\s(\d{3})/", $response, $matches)){
      $code=intval($matches[1]);
  }
else {
      return false;
  }


  /* see if code indicates success */
        if ($code != 200 && $code != 302 && $code != 304 && $code != 301){
            return false;
        }
else{
            print_r($matches);
            return true;
    }
}
    }
else{

        // error message
        echo "<p>Helaas heb je geen curl geinstalleerd. Hierdoor kun je de url's niet checken !</p>";
        exit;
}

?>
 
PHP hulp

PHP hulp

29/03/2024 11:10:29
 
Alfred

alfred

12/09/2008 19:37:00
Quote Anchor link
Als je mms:// vervangt door http:// werkt de stream ook. Dat zou betekenen dat je met curl deze ook kan doen.

Ik weet dat je met Fsockopen de port op 80 houdt je http://shoutcast.omroep.nl:8058 wel kan checken.

fsockopen($adress [http://shoutcast.omroep.nl:8058
] , $port [80] , &$errno, &$errstr, $timeout)

Dat zou betekenen dat je die url wel via port 80 kan doen. Hoe dat met cUrl werkt weet ik niet. misschien helpt dit. http://curl.haxx.se/docs/manual.html
 
Alfred

alfred

12/09/2008 23:54:00
Quote Anchor link
Op alle http adressen werkt het onderstaande script. Op mms heb ik getest met de volgende stream mms://arrowstream.atinet.nl/arrowrock Als je mms omzet naar http krijg je deze print.

HTTP/1.1 501 Not Implemented Server: Cougar/9.01.01.3862 Date: Fri, 12 Sep 2008 22:11:30 GMT Public: GET, POST, OPTIONS Pragma: no-cache Supported: com.microsoft.wm.srvppair, com.microsoft.wm.sswitch, com.microsoft.wm.predstrm, com.microsoft.wm.fastcache, com.microsoft.wm.startupprofile Connection: close

De toelichting is:

501 Not Implemented
The server does not support the functionality required to fulfill the request. This is the appropriate response when the server does not recognize the request method and is not capable of supporting it for any resource.

Ik heb hier geen zicht op maar het lijkt mij dat de mms-server deze request niet kan ondersteunen en daarom geen print geeft? Misschien heeft iemand anders hier een antwoord op.

Onderstaand geeft het op de URL's waar ik mee getest heb, netjes een print.

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
$port
= '80'; // waarde van de poort 80 voor het web
$url = 'http://radiolibra.dahstream.nl:8266'; // http://domeinnaam.ext
$time_out = '5'; // 0 = oneindig
    $curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL,$url);
    curl_setopt ($curl, CURLOPT_PORT,$port);
    curl_setopt ($curl, CURLOPT_HTTPPROXYTUNNEL,true);
    curl_setopt ($curl, CURLOPT_RETURNTRANSFER,true);
    curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT,$time_out);
    curl_setopt($curl, CURLOPT_HEADER, true);
    curl_setopt($curl, CURLOPT_NOBODY, true);     
    curl_exec ($curl);
    
$print = curl_exec ($curl);

    curl_close ($curl);

print $print;

  
  if(preg_match("/HTTP\/1\.[1|0]\s(\d{3})/", $print, $matches)){
      $code=intval($matches[1]);
  }

     else {
              return false;
  }


    if ($code != 200 && $code != 302 && $code != 304 && $code != 301){
            return false;
        }

    elseif  
            (print $matches){
            return true;
    }


    else{

        echo "<p>Helaas heb je geen curl geinstalleerd. Hierdoor kun je de url's niet checken !</p>";
        exit;
}

?>
Gewijzigd op 01/01/1970 01:00:00 door alfred
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.