Go Back   Winamp Forums > SHOUTcast > SHOUTcast Technical Support

Reply
Thread Tools Search this Thread Display Modes
Old 18th February 2005, 17:59   #1
MusiCodeZone
Junior Member
 
Join Date: Feb 2005
Posts: 10
Cannot connect with php to parse xml

I am using shoutcast, my home pc, cable modem, linksys router to stream to my webpage. The stream is up and available to the public, all indications are that the port is open, I can login to admin.cgi, I can view the xml, hear the stream, visitors can hear the stream, everything seems normal, yet I am unable to connect from my website using php.

<?php
$myip = "ip goes here";
$myport = "port goes here";
$conn = @fsockopen($myip, $myport, $errno, $errstr, 1);
if(!$conn) {
echo "$errstr - No connection";
} else {
echo "Success";
}
?>

Yes, I did insert the exact ip and port the server is using. The same ip and port I am able to admin on.

I am trying to retrieve the stats xml so I can parse it with php, but cannot get a connection from my website.

Is my router interfering, or is my ISP blocking the request?
I used http://www.radiotoolbox.com/online_t...ntheygetin.php
to test the port, and it says the port is open and the server exists. I am running out of ideas. Anyone have any ideas? I've looked all over the place, but have not found any answers. Certainly someone out there has had the same problem, huh?
I know there are drawbacks to using the home pc as a server, is this one of them?
Any help is appreciated.
MusiCodeZone is offline   Reply With Quote
Old 19th February 2005, 03:21   #2
NumbCore
Junior Member
 
Join Date: Feb 2005
Location: New Jersey
Posts: 49
Send a message via AIM to NumbCore
PHP Code:
<?php
$myip 
"ip goes here";
$myport "port goes here";

$conn = @fsockopen("$myip"$myport, &$errno, &$errstr3);
if(!
$conn) {
echo 
"Server Up";
} else {
echo 
"Server Down";
}
?>
Try that.
NumbCore is offline   Reply With Quote
Old 19th February 2005, 14:30   #3
MusiCodeZone
Junior Member
 
Join Date: Feb 2005
Posts: 10
Thanks for your response. Unfortunately, I had already tried that. I am thinking it is not a php coding error. PHP will return the same result either way you write it. Apparently, php doesn't seem to be too picky about the syntax in this case. I usually go for the "Readers Digest" version if it works because it's less typing and less reading.
Lazy
MusiCodeZone is offline   Reply With Quote
Old 24th February 2005, 13:48   #4
MusiCodeZone
Junior Member
 
Join Date: Feb 2005
Posts: 10
Can't anyone answer this question for me?
MusiCodeZone is offline   Reply With Quote
Old 24th February 2005, 15:19   #5
101
Major Dude
 
101's Avatar
 
Join Date: Jul 2004
Location: Argentina
Posts: 828
Send a message via ICQ to 101
Try setting a higher value for the timeout argument of fsockopen(), for example:

fsockopen($myip, $myport, $errno, $errstr, 10);

Also, remove the '@' in front of the function call so you can see if there's any warning.

Words are very unnecessary, they can only do harm, so enjoy the silence - Depeche Mode
Firemonger Project: Help spread Firefox
101 is offline   Reply With Quote
Old 24th February 2005, 17:01   #6
MusiCodeZone
Junior Member
 
Join Date: Feb 2005
Posts: 10
Thanks for the reply.
I had already tried that also. I have tried a number of different ways to code the php for this, but I don't think that is the problem.
It's probably the router or the ISP, but I am just guessing.
Thanks again.
MusiCodeZone is offline   Reply With Quote
Old 24th February 2005, 17:18   #7
101
Major Dude
 
101's Avatar
 
Join Date: Jul 2004
Location: Argentina
Posts: 828
Send a message via ICQ to 101
Nah.. if people can connect to your stream, then the script will connect with no probs. But the host where you run the script [your web server] could be blocking ports. You can try setting your DNAS port base to some well-known port [80, 21, 110] Anyway, you should get a PHP warning telling you what's going on, post the URL of your DNAS to test that code from my host.

Words are very unnecessary, they can only do harm, so enjoy the silence - Depeche Mode
Firemonger Project: Help spread Firefox
101 is offline   Reply With Quote
Old 24th February 2005, 18:49   #8
Jay
Moderator Alumni
 
Jay's Avatar
 
Join Date: May 2000
Location: Next Door
Posts: 8,888
likely it is the webserver, many cheap or paranoid hosts have really crappy php installations, buyer beware.
Jay is offline   Reply With Quote
Old 24th February 2005, 19:41   #9
MusiCodeZone
Junior Member
 
Join Date: Feb 2005
Posts: 10
I guess I assumed that since I haven't had a problem with any other PHP functionality, my host wasn't the problem.
Here is the stream address http://68.1.93.201:7000/listen.pls

Thanks for the assistance.
MusiCodeZone is offline   Reply With Quote
Old 24th February 2005, 19:56   #10
101
Major Dude
 
101's Avatar
 
Join Date: Jul 2004
Location: Argentina
Posts: 828
Send a message via ICQ to 101
I've tested that code from my local web server and from another host and it works just fine. Here's is the link to that code pointing to your DNAS, as you can see the prob is with your web server.

http://dm101.vaio-hosting.com/test.php

Words are very unnecessary, they can only do harm, so enjoy the silence - Depeche Mode
Firemonger Project: Help spread Firefox
101 is offline   Reply With Quote
Old 24th February 2005, 20:35   #11
MusiCodeZone
Junior Member
 
Join Date: Feb 2005
Posts: 10
Thank you so much for your help. Now, if my host is as helpful, I'll be in good shape!
MusiCodeZone is offline   Reply With Quote
Old 24th February 2005, 23:05   #12
MusiCodeZone
Junior Member
 
Join Date: Feb 2005
Posts: 10
No response from the host, but I found an opening by changing ports.
I switched the DNAS to port 20 and switched port forwarding to 20 - 21 range. I get a connection with php on port 21, but not port 20. The admin and stream are working on port 20. I thought this was sorta weird, but hey, whatever works.
Maybe this will help someone else if they ever have this problem in the future.
Thanks for the help everyone!
MusiCodeZone is offline   Reply With Quote
Old 24th February 2005, 23:13   #13
101
Major Dude
 
101's Avatar
 
Join Date: Jul 2004
Location: Argentina
Posts: 828
Send a message via ICQ to 101
That's because they won't block some well known ports, that's a good way to probe that they are actually blocking ports. If you use a paid host, ask them to open the port base of your DNAS, they should do it.

Words are very unnecessary, they can only do harm, so enjoy the silence - Depeche Mode
Firemonger Project: Help spread Firefox
101 is offline   Reply With Quote
Old 25th February 2005, 00:35   #14
MusiCodeZone
Junior Member
 
Join Date: Feb 2005
Posts: 10
Yeah, I'll have to do that because I just figured out that even though I can determine if the server is active on port 21 using php, I still cannot retrieve the xml file because it is only accessible on port 20. Ugh! The php has to be able to work on the same exact port in order to be able process the file request.
MusiCodeZone is offline   Reply With Quote
Old 25th February 2005, 00:36   #15
NumbCore
Junior Member
 
Join Date: Feb 2005
Location: New Jersey
Posts: 49
Send a message via AIM to NumbCore
I keep getting this error...

Quote:
[24-Feb-2005 20:23:28] PHP Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of fsockopen(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in /home/clashfm/public_html/includes/fuctions.php on line 2
This is the fuctions.php file...

PHP Code:
<?
function get_current_song ($host=''$port=''$text='') {
    
$conn = @fsockopen("$host"$port, &$errno, &$errstr1);
    if(!
$conn) {
        
fputs($conn,"GET /7.html HTTP/1.0\r\nUser-Agent: SHOUTcast Quick Song Status (Mozilla Compatible)\r\n\r\n");
        while(!
feof($conn)) {
            
$source .= fgets($conn1000);
         }
            
$source ereg_replace(".*<body>|</body>.*"""$source);
            
$data explode(","$source);
            if(
$data***91;1***93;) {
                echo 
$text.$data***91;6***93;;
            } else {
                echo 
"No broadcast Source";
            }
    } else {
        echo 
"Server Down";
    }
    
fpassthru($conn);
    
fclose($conn);
}
?>
Do you think it is related to this topic because fsockopen() fuction?
NumbCore is offline   Reply With Quote
Old 25th February 2005, 01:27   #16
MusiCodeZone
Junior Member
 
Join Date: Feb 2005
Posts: 10
Remove fpassthru($conn); and see if you get the same result. Just a hunch.
MusiCodeZone is offline   Reply With Quote
Old 25th February 2005, 03:27   #17
101
Major Dude
 
101's Avatar
 
Join Date: Jul 2004
Location: Argentina
Posts: 828
Send a message via ICQ to 101
Quote:
Originally posted by MusiCodeZone
Yeah, I'll have to do that because I just figured out that even though I can determine if the server is active on port 21 using php, I still cannot retrieve the xml file because it is only accessible on port 20. Ugh! The php has to be able to work on the same exact port in order to be able process the file request.
Look, to get the XML stats you use the port base of your DNAS, so.. if the script is able to connect to port 21 then you'll get the XML on that port [using a different code of course..]

@NumbCore: you get that warning because the errno and errstr arguments of fsockopen() are being passed by reference and as the warning says, that has been deprecated in newer versions of PHP. Just remove the reference operator '&' in front of those arguments.

Words are very unnecessary, they can only do harm, so enjoy the silence - Depeche Mode
Firemonger Project: Help spread Firefox
101 is offline   Reply With Quote
Old 25th February 2005, 14:32   #18
MusiCodeZone
Junior Member
 
Join Date: Feb 2005
Posts: 10
Quote:
Originally posted by 101
Look, to get the XML stats you use the port base of your DNAS, so.. if the script is able to connect to port 21 then you'll get the XML on that port [using a different code of course..]
I hoped it would work like that too, but it doesn't seem to.
The script connects on port 21 and returns true, but will not retrieve the xml (or even 7.html) on that port.
It appears the xml can only be gotten on port 20 which is the port the DNAS is running on, but php will not connect to that port.

I tried out the same basic code that NumCore submitted (with a couple of alterations), my result was this -
On port 21 - connection, but not a valid stream resource.
On port 20 - server down

So, I go to the admin page which is on port 20 and I pull up the xml page which is also on port 20. No problem.
Then I try the same with port 21 .... no admin page, no xml, no 7.html.

I understand it requires a different script to get the xml.

I think it boils down to having to get the web host to open up the same exact port the DNAS is using. Pretty frustrating. The host is less than responsive ... Sorta like beating a dead horse.
MusiCodeZone is offline   Reply With Quote
Old 25th February 2005, 14:54   #19
NumbCore
Junior Member
 
Join Date: Feb 2005
Location: New Jersey
Posts: 49
Send a message via AIM to NumbCore
Quote:
Originally posted by 101
@NumbCore: you get that warning because the errno and errstr arguments of fsockopen() are being passed by reference and as the warning says, that has been deprecated in newer versions of PHP. Just remove the reference operator '&' in front of those arguments.
Wrong. But I did it anyway.

Quote:
Originally posted by MusiCodeZone
Remove fpassthru($conn); and see if you get the same result. Just a hunch.
I commented out that line...and it worked!
// fpassthru($conn);
NumbCore is offline   Reply With Quote
Old 25th February 2005, 16:01   #20
101
Major Dude
 
101's Avatar
 
Join Date: Jul 2004
Location: Argentina
Posts: 828
Send a message via ICQ to 101
musiCode.. just change the DNAS port base to the port that is open on your web server, 21 in this case. The only prob about using port 21 is that usually you don't want to run something on a port assigned by default to another service, FTP in this case.

And numbcore, first make sure that you know what you're talking about, you got a warning on line 2 about the call to fsockopen() and you fixed it modifying the line 19 that has nothing to do with that warning...

/btw, that code is 'inverted'... you're trying to get 7.html when there's no connection, check your first IF statement..

Words are very unnecessary, they can only do harm, so enjoy the silence - Depeche Mode
Firemonger Project: Help spread Firefox

Last edited by 101; 25th February 2005 at 16:23.
101 is offline   Reply With Quote
Old 25th February 2005, 20:25   #21
NumbCore
Junior Member
 
Join Date: Feb 2005
Location: New Jersey
Posts: 49
Send a message via AIM to NumbCore
Haha! I keept asking myself why it said server offline when it really was online.

This is my new fuction...

PHP Code:
<?
function get_current_song ($host='67.159.26.123'$port='8000'$text='<b>Now Playing:</b><br>') {
    
$conn = @fsockopen($host$port$errno$errstr1);
    if(!
$conn) {
        echo 
"Server Down";
    } else {
        
fputs($conn,"GET /7.html HTTP/1.0\r\nUser-Agent: SHOUTcast Quick Song Status (Mozilla Compatible)\r\n\r\n");
        while(!
feof($conn)) {
            
$source .= fgets($conn1000);
        }
        
$source ereg_replace(".*<body>|</body>.*"""$source);
        
$data explode(","$source);
        
/*
        $data***91;0***93;: Current # of listeners
        $data***91;1***93;: Stream Status
        $data***91;2***93;: Peak # of listeners
        $data***91;3***93;: Max # of listeners allowed
        $data***91;4***93;: Current # of listeners
        $data***91;5***93;: Bitrate
        $data***91;6***93;: Current artist - track playing
        */
        
if($data***91;1***93; != "0") {
            echo 
$text.$data***91;6***93;;
        } else {
            echo 
"No broadcast Source";
        }
    }
    
fclose($conn);
}
?>
NumbCore is offline   Reply With Quote
Reply
Go Back   Winamp Forums > SHOUTcast > SHOUTcast Technical Support

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump