Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 8 of 8

This is a discussion on fsockopen(): unable to connect... in the Shared & Semi-Dedicated forum
Hello, i am trying to set up a page which tells you if my radio server is online or not. I have had a word ...

  1. #1
    Loyal Client
    Join Date
    Jan 2002
    Posts
    224

    fsockopen(): unable to connect...

    Hello,
    i am trying to set up a page which tells you if my radio server is online or not.
    I have had a word with the people who host my radio, and they said the script works fine, but the host i am on "may block outbound connections.

    Can anyone offer any advice on why i get this error:

    Warning: fsockopen(): unable to connect to 213.48.102.229:9150 in /home/sosolidp/public_html/radio_stats.php on line 25
    Here is some code, line 25 is "$page .= fgets($scfp, 1000);"

    PHP Code:
    $scfp fsockopen("$scip"$scport, &$errno, &$errstr30);
     if(!
    $scfp) {
      
    $scsuccs=1;
    echo
    ''.$scdef.' is Offline'
     }
    if(
    $scsuccs!=1){
     
    fputs($scfp,"GET /admin.cgi?pass=$scpass&mode=viewxml HTTP/1.0\r\nUser-Agent: SHOUTcast Song Status (Mozilla Compatible)\r\n\r\n");
     while(!
    feof($scfp)) {
     
    $page .= fgets($scfp1000);
     } 

  2. #2
    Jag Veteran
    Join Date
    Sep 2002
    Posts
    650
    FreeFall,

    First thing I would suggest you to do is adding error diagnostic. There are quite a few factors to consider when connection can't be established and blocking (or filtering) is only one of them.

    Let us know how it goes.

  3. #3
    Loyal Client
    Join Date
    Jan 2002
    Posts
    224
    LOL, i have no idea how to do that, i will ask my radio hosts again maybe there is something wrong/another solution :P

  4. #4
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    Since it looks like you are just trying to connect to a web server, you may want to try using fopen() (or even file()) instead of fscock open. With fopen()/file() you can pass a URL as the file path. Then you can just start fgets()ing, you don't need to start talking HTTP with fputs().

    Example:
    fopen('http://213.48.102.229:9150/admin.cgi?pass=$scpass&mode=viewxml', 'r');

    file() would make it even easier, as it will return just the content of the request (without the headers to parse out) in an array when you simply pass the URL.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  5. #5
    Loyal Client
    Join Date
    Jan 2002
    Posts
    224
    if i have $scfp = file($scip, $scport, &$errno, &$errstr, 30); i get:
    Warning: file() expects at most 2 parameters, 5 given in /home/sosolidp/public_html/radio_stats.php on line 25

    If i use fopen i get:
    Warning: fopen() expects at most 4 parameters, 5 given

    If you cannot already tell, i know nothing about PHP

  6. #6
    Jag Veteran
    Join Date
    Sep 2002
    Posts
    650
    Jason,

    That might work, but HTTP protocol also allows to send data in 'chunks', in which case the actual data could be mixed with HTTP headers when you just read everything.

    Besides, we dont know why fsockopen doesn't work, what would be the point of substituting it with fopen()?
    Even if there is a problem with fsockopen, checking the error first looks like the best course of action time-wise.

    FreeFall:
    Add the following after the first line (with fsockopen):
    PHP Code:
    print "Error code: $errno, Error string: $errstr<BR>\n"
    then try to run the script again and let us know what response you get.

  7. #7
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    All you need is

    $scfp = file('<url as above>'); {or}
    $scfp = fopen('<url as above>', 'r');

    If you use file() and it works, $scfp will be an array that will contain whatever the server r eturns. You should then use this command to condence it into a single string as you would get with the method you posted in your sample:

    $page = implode('', $scfp);

    You'll probably want to comment out (recommended) or remove the block of code starting with the fsockopen() call and likely ending with fclose() to avoid any problems. Then insert the above two lines in their place.

    With fopen(), $scfp will contain a file handle the same way that an fsockopen() call would. You'll want to comment out (again, recommended) or remove the fsockopen() and fputs() lines, but leave the fgets() and fclose() lines alone. In this case, $page will contain both the content that the site returns and the headers. I'd suspect that farther down in your code there are lines to handle this, so this might be the better route to try.

    Hope this helps.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  8. #8
    Loyal Client
    Join Date
    Jan 2002
    Posts
    224
    well, i emailed support, and the port was closed. It is open now and everything seems to work
    thanks for your support gerilya and Jason

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •