View previous topic :: View next topic |
Author |
Message |
Nanou
Joined: 24 Nov 2009 Posts: 30
|
Posted: Fri Nov 27, 2009 10:36 pm Post subject: |
|
|
bon, j'y arrive pas, je comprends pas. Je dois vraiment étudier tout ca...j'y vais les yeux fermés merde lolll....
Écoute merci encore pour ton aide...Je vais me débrouiller moi meme, je crois que c'est la meilleure facon d'apprendre Je vais fouiller tous le forum avec d'autre exemples et sur mr.google aussi.
Si je réussit, je vais laissé une note ici.
Amicalement.
|
|
Back to top |
|
|
rec91402
Joined: 14 Nov 2009 Posts: 32
|
Posted: Sat Nov 28, 2009 3:12 am Post subject: |
|
|
Les corrections à la syntaxe ont fait
Code: |
<?php
/**
* Sample icecast status querying from PHP
*
* This is only a very simple sample.
* When you have multiple mounts, you should extend on it.
*
* Use more info from status2.xsl if needed.
* This is a very basic display, you'll have to create your own look and feel
* and add eventual JQuerry, Mootools or other javascript in a RESTFUL environment
* to allow auto refresh.
*/
/**
* Connection parameters helper class
* Please fill in the blanks here
*/
class icecastParams
{
public $host = 'YOUR URL IP HERE!' ; // Your Icecast host name or IP
public $port = '8000' ; // Your icecast Port
} // class icecastParams
/**
* Main icecast connection and data management
*
* This should be modified according to your needs.
* It's only a guideline on how to talk with icecast xsl based services.
*/
class icecastClient
{
private $p = null ; // Server parameters
private $errstr = '' ; // socket Error string
private $errno = '' ; // socket Error number
private $number = '10' ; // socket timeout
/**
* Creates an instance of icecastClient
*/
public function __construct()
{
$this->p = new icecastParams() ;
if ( empty( $this->p->host ) ) {
throw new Exception( 'Please setup your icecast host name' ) ;
}
if ( empty( $this->p->port ) ) {
throw new Exception( 'Please setup your icecast access port' ) ;
}
} // __construct
/**
* Main method, Connects to icecast, grabs info and build response.
* @return Response string
*/
public function getServerInfo()
{
$data = '' ;
$fp = $this->serverConnect() ;
if ( $fp ) {
if ( $fp['Status'] == 'Offline' ) {
$data = 'Radio Offline' ;
} else {
// feel free to add other things in HtmlResponse service call
$datax = $this->setHtmlResponse( $fp['Listeners'], $fp['MountPoint'] ) ;
}
} else {
$datax = "Icecast Server Unavailable. Reason: $this->errno, $this->errstr" ;
}
return $datax;
} // getServerInfo
/**
* Connects to icecast server and grabs
*
* @return Array with information about service
*/
private function serverConnect()
{
$fp = @fsockopen( $this->p->host, $this->p->port, $this->errno, $this->errstr, $this->number ) ;
if ( !$fp )
return false ;
$data = '' ;
fputs( $fp, "GET /status2.xsl HTTP/1.1\nUser-Agent:Mozilla\n\n" ) ; // grab status2.xsl
if ( !feof($fp ) ) {
$data = fread( $fp, 31337 ) ;
usleep( 500000 ) ;
}
fclose( $fp ) ;
$status = empty( $data) ? 0 : 1 ; // if no data, nothing to listen to...
if ( $status == 0 ) {
return array( 'Offline' ) ;
}
$atmp = explode( "\n", $data ) ;
// if junk data is shown, uncomment next line to get info via dump and give good indice.
//echo "<pre>" ; var_dump( $atmp ) ; echo "</pre>============\n" ;
$data = $atmp[9] ; // Note: indice may vary depending on your settings. See dump for fitting.
$data = explode( ',', $data ) ;
return array( 'Status' => 'Online',
'MountPoint' => $data[0],
'Listeners' => $data[3],
'Title' => $data[5] ) ;
} // serverConnect
/**
* Very basic Htlm response, you should change it according to your needs
*/
private function setHtmlResponse( $listeners, $title ) {
return 'Listeners: ' . $listeners . '<br />Title: ' . $title . '<br />' ;
}
} // class icecastClient
// test code
$radio = new icecastClient() ;
echo $radio->getServerInfo() ;
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group subRebel style by ktauber
|