Announcement

Collapse
No announcement yet.

PHP fsockopen(): shared hosting plz help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP fsockopen(): shared hosting plz help

    Hello
    this is my first post, i have received a lot of help from here was hoping i can get some more help.

    i want to put up Now Playing song on my website. I have found all the PHP scripts that are on the internet. But my server is hosted on godaddy. When i try to run the script i get this error

    Warning: fsockopen(): unable to connect to xxx.xx.xxx.xxxort in /home/eznom34/public_html/s7/xxxxx/radio_stats.php on line 16
    You're Listening To dhoom24-7 Radio. is Offline

    Called the hosting people, They say that their shared hosting plans dont allow fsock command.

    I was wondering if there is anyother way to make this work

    Really appreciate your help
    Last edited by mauliksp; 14 October 2007, 02:03.

  • #2
    Untested but try the following (change IP and port as needed):
    PHP Code:
    <?

    $ip
    ="127.0.0.1";
    $port=8000;
    $message="%s";

    function 
    streaminfo($ip,$port$message){
      
    $curl=1;
      if(
    $curl==1){
       
    $stream = `curl http://$ip:$port/7.html -A \"Mozilla\"`;
       
    $fp=1;
      }
      else{
        
    $fp [email protected]fsockopen ($ip$port, &$errno, &$errstr2);
      }
      if(!
    $fp){
        echo 
    "Could not connect to <b>{$ip}:{$port}</b> ({$errno}) - {$errstr}\n";
       } 
       else{
         if(
    $curl!=1){
           
    fputs ($fp"GET /7 HTTP/1.1\r\nUser-Agent:Mozilla\r\n\r\n");
           while (!
    feof($fp)){
             
    $stream fgets($fp,1024);
           }
         }
         list(,
    $stream) = explode("<body>",$stream);
         list(
    $stream) = explode("</body>",$stream);
         list(
    $user$status$user_peak$user_max, ,$bitrate$song) = explode(",",$stream);
         if(
    $status=="0"){
           echo
    "Offline";
         } 
         else{
           
    $status="Online";
           
    $message=str_replace("%up"$user_peak$message);
           
    $message=str_replace("%um"$user_max$message);
           
    $message=str_replace("%u"$user$message);
           
    $message=str_replace("%st"$status$message);
           
    $message=str_replace("%b"$bitrate$message);
           
    $message=str_replace("%s"$song$message);
           echo 
    $message;
         }
       if(
    $curl!=1){
         
    fclose($fp);
       }
      }
    }
    streaminfo($ip$port$message);

    ?>
    Tom

    Comment


    • #3
      hello
      Thank you so much for replying
      i did use your code by replacing this

      $ip="72.211.208.47";
      $port=8001;
      $message="Dhoom 24-7";

      all it shows me is "Dhoom 24-7"

      no errors either

      the info provided is the real port and ip
      do i need to include the shoutcast password or anything

      The stream is on currently

      once again thanks

      Comment


      • #4
        There are variables for the message:

        %up = peak # of listeners
        %um = max # of listeners
        %u = current # of listeners
        %st = status
        %b = bitrate
        %s = current song

        So the way you defined the message the info is not in there. Try the following:
        $message="Dhoom 24-7: %s"

        Tom

        Comment


        • #5
          Hi
          ya it still doesnt display the current song still only displays Dhoom 24-7

          if i only keep %s it doesnt display anything

          Comment


          • #6
            hello
            i am not sure if this could be a problem but

            $stream = `curl <a href="http://" target="_blank">http://</a>$ip:$port/7.html -A \"Mozilla\"` ;

            it comments out everything after "_blank"http: because of //

            Comment


            • #7
              Yes, the forum software added some tags around http://. I've gone back and gotten rid of them and turned that feature off in the post with the php code. Try the code posted above again. Only change was the line you referenced should be: $stream = `curl http://$ip:$port/7.html -A \"Mozilla\"`;

              Tom

              Comment


              • #8
                hey
                sorry to bother you but its still commenting out everything in that like after http://

                <?php

                $ip="72.211.208.47";
                $port= 8001;
                $message="%s";

                function streaminfo($ip,$port, $message){
                $curl=1;
                if($curl==1){
                $stream = `curl http://$ip:$port/7.html -A \"Mozilla\"`;
                $fp=1;
                }
                else{
                $fp [email protected] ($ip, $port, &$errno, &$errstr, 2);
                }
                if(!$fp){
                echo "Could not connect to <b>{$ip}:{$port}</b> ({$errno}) - {$errstr}\n";
                }
                else{
                if($curl!=1){
                fputs ($fp, "GET /7 HTTP/1.1\r\nUser-Agent:Mozilla\r\n\r\n");
                while (!feof($fp)){
                $stream = fgets($fp,1024);
                }
                }
                list(,$stream) = explode("<body>",$stream);
                list($stream) = explode("</body>",$stream);
                list($user, $status, $user_peak, $user_max, ,$bitrate, $song) = explode(",",$stream);
                if($status=="0"){
                echo"Offline";
                }
                else{
                $status="Online";
                $message=str_replace("%up", $user_peak, $message);
                $message=str_replace("%um", $user_max, $message);
                $message=str_replace("%u", $user, $message);
                $message=str_replace("%st", $status, $message);
                $message=str_replace("%b", $bitrate, $message);
                $message=str_replace("%s", $song, $message);
                echo $message;
                }
                if($curl!=1){
                fclose($fp);
                }
                }
                }
                streaminfo($ip, $port, $message);

                ?>



                where it says url submitted by user it should be http://

                Comment


                • #9
                  Hmmm... Maybe curl is not available to you either because the code you posted above works fine on the server I have access to.

                  Tom

                  Comment


                  • #10
                    One more thing. It looks like GoDaddy uses a proxy based on some posts so give this a try:

                    PHP Code:
                    <?php

                    $ip
                    ="72.211.208.47";
                    $port8001;
                    $message="%s";

                    function 
                    streaminfo($ip,$port$message){
                    $curl=1;
                    if(
                    $curl==1){
                    $url "http://$ip:$port/7.html";

                    $ch curl_init();
                    curl_setopt ($chCURLOPT_URL$url);
                    curl_setopt($chCURLOPT_USERAGENT'SHOUTcast Info Getter (Mozilla)');
                    curl_setopt ($chCURLOPT_RETURNTRANSFER1);
                    curl_setopt ($chCURLOPT_PROXYTYPECURLPROXY_HTTP);
                    curl_setopt ($chCURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");
                    curl_setopt ($chCURLOPT_TIMEOUT5);
                    $stream curl_exec ($ch);
                    if(
                    is_int($response)) {
                        die(
                    "Errors: " curl_errno($ch) . " : " curl_error($ch));
                    }
                    curl_close ($ch);
                    $fp=1;
                    }
                    else{
                    $fp [email protected]fsockopen ($ip$port, &$errno, &$errstr2);
                    }
                    if(!
                    $fp){
                    echo 
                    "Could not connect to <b>{$ip}:{$port}</b> ({$errno}) - {$errstr}\n";
                    }
                    else{
                    if(
                    $curl!=1){
                    fputs ($fp"GET /7 HTTP/1.1\r\nUser-Agent:Mozilla\r\n\r\n");
                    while (!
                    feof($fp)){
                    $stream fgets($fp,1024);
                    }
                    }
                    list(,
                    $stream) = explode("<body>",$stream);
                    list(
                    $stream) = explode("</body>",$stream);
                    list(
                    $user$status$user_peak$user_max, ,$bitrate$song) = explode(",",$stream);
                    if(
                    $status=="0"){
                    echo
                    "Offline";
                    }
                    else{
                    $status="Online";
                    $message=str_replace("%up"$user_peak$message);
                    $message=str_replace("%um"$user_max$message);
                    $message=str_replace("%u"$user$message);
                    $message=str_replace("%st"$status$message);
                    $message=str_replace("%b"$bitrate$message);
                    $message=str_replace("%s"$song$message);
                    echo 
                    $message;
                    }
                    if(
                    $curl!=1){
                    fclose($fp);
                    }
                    }
                    }
                    streaminfo($ip$port$message);

                    ?>
                    Tom

                    Comment


                    • #11
                      hello
                      thank you for working on this

                      but its still doing the same thing Blank page

                      i called godaddy and they said their servers do support cURL

                      and also does this script automatically update when the song changes

                      thanks once again

                      Comment


                      • #12
                        hi
                        forgot to include this before here is the link to the script on godaddy servers.
                        "www.dhoom24-7.com/teststream.php"

                        Comment


                        • #13
                          This script will pull the data once and display it, so no it won't auto update by itself. You can use the above script with some javascript to create an AJAX solution which will autoupdate without refreshing the whole page at a given interval.

                          Looking at GoDaddy's support pages there seems to be some conflicting data: http://help.godaddy.com/search.php?t...q=curl&x=0&y=0
                          There they claim fsockopen works. Also from there they only mention the proxy for cURL when using a secure connection so perhaps try commenting out the proxy line and seeing if that changes anything.

                          Tom

                          Comment


                          • #14
                            hi
                            it still doesnt work
                            i am on the phone with godaddy now and they are saying that the servers do support fsockopen
                            but i am using the script provided here
                            "http://www.streamsolutions.co.uk/index.php?page=scripts"
                            teh Atomic Statistics

                            when i run it on the godaddy server i get this error
                            Warning: fsockopen(): unable to connect to 72.211.208.47:8001 in /home/content/m/a/u/maulishahp/html/index.php on line 26
                            This server is currently offline


                            I also showed them the curl script adn they are like something could be wrong with the script

                            do you recommend any other hosts that will support this without any problems

                            Comment


                            • #15
                              I'll try it on a shared host I have had for awhile once I get my cpanel password reset over there. There are a couple other ways to get this data to your website (radiotoolbox for instance, it runs on a PC and gets the info to the website by a URL call/php script or FTP).

                              Tom

                              Comment

                              Working...
                              X