Visualizzazione dei risultati da 1 a 5 su 5

Discussione: Now Playing in PHP

  1. #1

    Now Playing in PHP

    Ciao!

    sto cercando di far partire un Now Playing per la nostra webradio che ha attualmente due server che possono andare.

    Quello che sto cercando di fare è interrogare prima il primo server, e se quello non è attivo, interrogare il secondo che invece è sempre attivo.

    vi allego lo script che ho trovato su internet e che funziona per, appunto, un solo server.

    codice:
    <?php 
    include("icecast.current.class.php"); 
    
    $icecast = new icecast(); 
    
    $icecast->host = "stream.lanostraradio.com"; 
    $icecast->port = 8000; 
    $icecast->mount = "mount1"; 
    $icecast->user = "user"; 
    $icecast->passwd = "passwd"; 
    
    function elapsedtime($seconds) { 
    if ($seconds > 86400) { 
    $seconds -= 86400; 
    return(gmdate("j\d H:i:s", $seconds)); 
    } else 
    return(gmdate("H:i:s", $seconds)); 
    } 
    
    if ($icecast->openstats()) { 
    // We got the XML, gogogo!.. 
    
    echo "Su Radio Gwen strimpella:
    
    "; 
    echo $icecast->GetCurrent(); 
    
    }
    
     else { 
    echo "Non suona niente"; 
    } 
    ?>
    come si fare un If/Else?

    grazie!

  2. #2

    Re: Now Playing in PHP

    io controllerei con fsockopen per vedere se il primo server è online, se lo è imposti le variabili riferite al primo, altrimenti imposti quelle del secondo:

    Codice PHP:
    <?php 
    include("icecast.current.class.php"); 

    $icecast = new icecast(); 

    $fp fsockopen("stream.lanostraradio1.com"8000, &$errno, &$errstr30); //forse 30 secondi sono troppi
    if($fp
            { 
             
    $icecast->host "stream.lanostraradio1.com"
             
    $icecast->port 8000
             
    $icecast->mount "mount1"
             
    $icecast->user "user"
             
    $icecast->passwd "passwd"
            } 
    else 
         {
          
    //impostazioni secondo server
          
    $icecast->host "stream.lanostraradio2.com"
          
    $icecast->port 8000
          
    $icecast->mount "mount1"
          
    $icecast->user "user"
          
    $icecast->passwd "passwd"
         }

    function 
    elapsedtime($seconds) { 
    if (
    $seconds 86400) { 
    $seconds -= 86400
    return(
    gmdate("j\d H:i:s"$seconds)); 
    } else 
    return(
    gmdate("H:i:s"$seconds)); 


    if (
    $icecast->openstats()) { 
    // We got the XML, gogogo!.. 

    echo "[b]Su Radio Gwen strimpella:[/b]

    "

    echo 
    $icecast->GetCurrent(); 

    }

     else { 
    echo 
    "Non suona niente"

    ?>

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2010
    Messaggi
    323

  4. #4
    Dunque, ho provato, ma sembra si fermi solo all'IF dando poi il seguente messaggio nell'output:

    HTTP/1.0 401 Authentication RequiredWWW-Authenticate: Basic realm="Icecast2 Server"You need to authenticate

  5. #5
    beh se il server risponde con una rischiesta di autenticazione vuol dire che è attivo

    forse l'esempio cho eho postato andrebbe raffinato, ma non so neanche io come...

    in alternativa puoi provare con "file_exist"

    mi pare di aver capito se il server Icecast crei dinamicamente questo file su richiesta:
    http://serverort/admin/stats.xml

    in teoria basterebbe controllarne l'esistenza con file_exist per capire se il server è online:

    esempio:

    <?php
    $filename = '/path/to/foo.txt';

    if (file_exists($filename)) {
    echo "The file $filename exists";
    } else {
    echo "The file $filename does not exist";
    }
    ?>

    che applicato al tuo caso dovrebbe essere così:
    Codice PHP:
    <?php 
    include("icecast.current.class.php"); 

    $icecast = new icecast(); 

    if (
    file_exists("http://stream.lanostraradio1.com:8000/admin/stats.xml")) 
            { 
             
    $icecast->host "stream.lanostraradio1.com"
             
    $icecast->port 8000
             
    $icecast->mount "mount1"
             
    $icecast->user "user"
             
    $icecast->passwd "passwd"
            } 
    else 
         {
          
    //impostazioni secondo server
          
    $icecast->host "stream.lanostraradio2.com"
          
    $icecast->port 8000
          
    $icecast->mount "mount1"
          
    $icecast->user "user"
          
    $icecast->passwd "passwd"
         }

    function 
    elapsedtime($seconds) { 
    if (
    $seconds 86400) { 
    eccetera....
    }

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.