fsockopen error need some help thanks

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yoko

    fsockopen error need some help thanks


    So I am using php version 4.3.9 and lets say i have a file on the server
    called tester.php

    so i am using fsockopen to point to that file but it gives me a error below.



    $fh = @fsockopen("htt p://www.mysite.com/teter.php", "80", $errno, $errstr,
    180);

    111 Connection refused

    This server is linux Redhat Enterprise with Apache 2.x

    Is there anything i need to edit in the php.ini file or apache file.



    Thanks...


  • petersprc

    #2
    Re: fsockopen error need some help thanks

    If using fsockopen, try without the "http://", since fsockopen expects
    a host. You could also use reafile, file_get_conten ts, fopen, etc. on
    a URL.

    Yoko wrote:
    So I am using php version 4.3.9 and lets say i have a file on the server
    called tester.php
    >
    so i am using fsockopen to point to that file but it gives me a error below.
    >
    >
    >
    $fh = @fsockopen("htt p://www.mysite.com/teter.php", "80", $errno, $errstr,
    180);
    >
    111 Connection refused
    >
    This server is linux Redhat Enterprise with Apache 2.x
    >
    Is there anything i need to edit in the php.ini file or apache file.
    >
    >
    >
    Thanks...

    Comment

    • Yoko

      #3
      Re: fsockopen error need some help thanks

      I get this error when i turn on the error warnings in the php.ini file

      Warning: fsockopen(): unable to connect to www.fetchads.com:80 in /var/www/vhosts/fetchads.com/httpdocs/fsock/index.php
      on line 62


      Hello petersprc,
      If using fsockopen, try without the "http://", since fsockopen expects
      a host. You could also use reafile, file_get_conten ts, fopen, etc. on
      a URL.
      >
      Yoko wrote:
      >
      >So I am using php version 4.3.9 and lets say i have a file on the
      >server called tester.php
      >>
      >so i am using fsockopen to point to that file but it gives me a error
      >below.
      >>
      >$fh = @fsockopen("htt p://www.mysite.com/teter.php", "80", $errno,
      >$errstr, 180);
      >>
      >111 Connection refused
      >>
      >This server is linux Redhat Enterprise with Apache 2.x
      >>
      >Is there anything i need to edit in the php.ini file or apache file.
      >>
      >Thanks...
      >>

      Comment

      • petersprc

        #4
        Re: fsockopen error need some help thanks

        Try this:

        $sock = fsockopen('the. site', 80, $errno, $errstr, 15);

        Yoko wrote:
        I get this error when i turn on the error warnings in the php.ini file
        >
        Warning: fsockopen(): unable to connect to www.fetchads.com:80 in /var/www/vhosts/fetchads.com/httpdocs/fsock/index.php
        on line 62
        >
        >
        Hello petersprc,
        >
        If using fsockopen, try without the "http://", since fsockopen expects
        a host. You could also use reafile, file_get_conten ts, fopen, etc. on
        a URL.

        Yoko wrote:
        So I am using php version 4.3.9 and lets say i have a file on the
        server called tester.php
        >
        so i am using fsockopen to point to that file but it gives me a error
        below.
        >
        $fh = @fsockopen("htt p://www.mysite.com/teter.php", "80", $errno,
        $errstr, 180);
        >
        111 Connection refused
        >
        This server is linux Redhat Enterprise with Apache 2.x
        >
        Is there anything i need to edit in the php.ini file or apache file.
        >
        Thanks...
        >

        Comment

        • saddor@gmail.com

          #5
          Re: fsockopen error need some help thanks

          Very simple my friend

          Solution One
          <?php
          $host = "www.example.co m";
          $fp = fsockopen($host , 80, $errno, $errstr, 30);
          if (!$fp) {
          echo "$errstr ($errno)<br />\n";
          } else {
          $out = "GET / HTTP/1.1\r\n";
          $out .= "Host: $host\r\n";
          $out .= "Connection : Close\r\n\r\n";

          fwrite($fp, $out);
          while (!feof($fp)) {
          echo fgets($fp, 128);
          }
          fclose($fp);
          }
          ?>

          Option 2 (PHP 4 and if the server allow) :
          $file = file_get_conten t("http://www.example.com/test.php");

          Option 3:
          $f = fopen("http://www.example.com/test.php","r");
          while ($r = fread($f, 1024)
          print $r;

          fclose($f);



          Is that useful for you?

          --
          Cesar Rodas
          http://www.phpclasses.org/grank (A PHP implementation of PageRank)


          On Nov 20, 7:40 pm, Yoko <n...@na.cawrot e:
          So I am using php version 4.3.9 and lets say i have a file on the server
          called tester.php
          >
          so i am using fsockopen to point to that file but it gives me a error below.
          >
          $fh = @fsockopen("htt p://www.mysite.com/teter.php", "80", $errno, $errstr,
          180);
          >
          111 Connection refused
          >
          This server is linux Redhat Enterprise with Apache 2.x
          >
          Is there anything i need to edit in the php.ini file or apache file.
          >
          Thanks...

          Comment

          • Andy Hassall

            #6
            Re: fsockopen error need some help thanks

            On 25 Nov 2006 05:53:54 -0800, saddor@gmail.co m wrote:
            >Solution One
            ><?php
            >$host = "www.example.co m";
            >$fp = fsockopen($host , 80, $errno, $errstr, 30);
            >if (!$fp) {
            echo "$errstr ($errno)<br />\n";
            >} else {
            $out = "GET / HTTP/1.1\r\n";
            $out .= "Host: $host\r\n";
            $out .= "Connection : Close\r\n\r\n";
            >
            fwrite($fp, $out);
            while (!feof($fp)) {
            echo fgets($fp, 128);
            }
            fclose($fp);
            >}
            >?>
            This has a common but serious mistake - you're claiming to be an HTTP/1.1
            client, but you haven't implemented Chunked transfer encoding. This is a
            mandatory requirement for HTTP/1.1 clients, and it's quite common that servers
            use it. If you don't handle it, the data will appear to be "corrupted" .

            The other solutions you posted use PHP's built-in HTTP user agent code, which
            does handle this encoding correctly. Alternatively the code above could be
            changed to use HTTP/1.0.

            --
            Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
            http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

            Comment

            • The GOsh! :D

              #7
              Re: fsockopen error need some help thanks

              Good point... Thanks you...
              Here's the new code.

              <?php
              $host = "www.example.co m";
              $fp = fsockopen($host , 80, $errno, $errstr, 30);
              if (!$fp) {
              echo "$errstr ($errno)<br />\n";
              } else {

              $out = "GET / HTTP/1.0\r\n";
              $out .= "Host: $host\r\n";
              $out .= "Connection : Close\r\n\r\n";

              fwrite($fp, $out);
              while (!feof($fp)) {
              echo fgets($fp, 128);
              }
              fclose($fp);
              }

              ?>


              On Nov 25, 10:15 am, Andy Hassall <a...@andyh.co. ukwrote:
              On 25 Nov 2006 05:53:54 -0800, sad...@gmail.co m wrote:
              >
              >
              >
              Solution One
              <?php
              $host = "www.example.co m";
              $fp = fsockopen($host , 80, $errno, $errstr, 30);
              if (!$fp) {
              echo "$errstr ($errno)<br />\n";
              } else {
              $out = "GET / HTTP/1.1\r\n";
              $out .= "Host: $host\r\n";
              $out .= "Connection : Close\r\n\r\n";
              >
              fwrite($fp, $out);
              while (!feof($fp)) {
              echo fgets($fp, 128);
              }
              fclose($fp);
              }
              ?This has a common but serious mistake - you're claiming to be an HTTP/1.1
              client, but you haven't implemented Chunked transfer encoding. This is a
              mandatory requirement for HTTP/1.1 clients, and it's quite common that servers
              use it. If you don't handle it, the data will appear to be "corrupted" .
              >
              The other solutions you posted use PHP's built-in HTTP user agent code, which
              does handle this encoding correctly. Alternatively the code above could be
              changed to use HTTP/1.0.
              >
              --
              Andy Hassall :: a...@andyh.co.u k ::http://www.andyh.co.ukhttp://www.and....co.uk/space:: disk and FTP usage analysis tool

              Comment

              • The GOsh! :D

                #8
                Re: fsockopen error need some help thanks

                This is another Solution is this, but think that you'll need to analize
                the headers for decompress is the content is compressed or am I wrong?:

                <?php
                $host = "www.example.co m";
                $fp = fsockopen($host , 80, $errno, $errstr, 30);
                if (!$fp) {
                echo "$errstr ($errno)<br />\n";
                } else {
                $out = "GET / HTTP/1.1\r\n";
                $out .= "Host: $host\r\n";
                $out .= "Accept-Language: en-us, en;q=0.50\r\n";
                $out .= "Accept-Encoding: gzip, deflate, compress;q=0.9\ r\n";
                $out .= "Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66\r\n";
                $out .= "Connection : Close\r\n\r\n";

                fwrite($fp, $out);
                while (!feof($fp)) {
                echo fgets($fp, 128);
                }
                fclose($fp);
                }

                ?>


                On Nov 25, 10:15 am, Andy Hassall <a...@andyh.co. ukwrote:
                On 25 Nov 2006 05:53:54 -0800, sad...@gmail.co m wrote:
                >
                >
                >
                Solution One
                <?php
                $host = "www.example.co m";
                $fp = fsockopen($host , 80, $errno, $errstr, 30);
                if (!$fp) {
                echo "$errstr ($errno)<br />\n";
                } else {
                $out = "GET / HTTP/1.1\r\n";
                $out .= "Host: $host\r\n";
                $out .= "Connection : Close\r\n\r\n";
                >
                fwrite($fp, $out);
                while (!feof($fp)) {
                echo fgets($fp, 128);
                }
                fclose($fp);
                }
                ?This has a common but serious mistake - you're claiming to be an HTTP/1.1
                client, but you haven't implemented Chunked transfer encoding. This is a
                mandatory requirement for HTTP/1.1 clients, and it's quite common that servers
                use it. If you don't handle it, the data will appear to be "corrupted" .
                >
                The other solutions you posted use PHP's built-in HTTP user agent code, which
                does handle this encoding correctly. Alternatively the code above could be
                changed to use HTTP/1.0.
                >
                --
                Andy Hassall :: a...@andyh.co.u k ::http://www.andyh.co.ukhttp://www.and....co.uk/space:: disk and FTP usage analysis tool

                Comment

                • The GOsh! :D

                  #9
                  Re: fsockopen error need some help thanks

                  This is another Solution is this, but think that you'll need to analize
                  the headers for decompress is the content is compressed or am I wrong?:

                  <?php
                  $host = "www.example.co m";
                  $fp = fsockopen($host , 80, $errno, $errstr, 30);
                  if (!$fp) {
                  echo "$errstr ($errno)<br />\n";
                  } else {
                  $out = "GET / HTTP/1.1\r\n";
                  $out .= "Host: $host\r\n";
                  $out .= "Accept-Language: en-us, en;q=0.50\r\n";
                  $out .= "Accept-Encoding: gzip, deflate, compress;q=0.9\ r\n";
                  $out .= "Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66\r\n";
                  $out .= "Connection : Close\r\n\r\n";

                  fwrite($fp, $out);
                  while (!feof($fp)) {
                  echo fgets($fp, 128);
                  }
                  fclose($fp);
                  }

                  ?>


                  On Nov 25, 10:15 am, Andy Hassall <a...@andyh.co. ukwrote:
                  On 25 Nov 2006 05:53:54 -0800, sad...@gmail.co m wrote:
                  >
                  >
                  >
                  Solution One
                  <?php
                  $host = "www.example.co m";
                  $fp = fsockopen($host , 80, $errno, $errstr, 30);
                  if (!$fp) {
                  echo "$errstr ($errno)<br />\n";
                  } else {
                  $out = "GET / HTTP/1.1\r\n";
                  $out .= "Host: $host\r\n";
                  $out .= "Connection : Close\r\n\r\n";
                  >
                  fwrite($fp, $out);
                  while (!feof($fp)) {
                  echo fgets($fp, 128);
                  }
                  fclose($fp);
                  }
                  ?This has a common but serious mistake - you're claiming to be an HTTP/1.1
                  client, but you haven't implemented Chunked transfer encoding. This is a
                  mandatory requirement for HTTP/1.1 clients, and it's quite common that servers
                  use it. If you don't handle it, the data will appear to be "corrupted" .
                  >
                  The other solutions you posted use PHP's built-in HTTP user agent code, which
                  does handle this encoding correctly. Alternatively the code above could be
                  changed to use HTTP/1.0.
                  >
                  --
                  Andy Hassall :: a...@andyh.co.u k ::http://www.andyh.co.ukhttp://www.and....co.uk/space:: disk and FTP usage analysis tool

                  Comment

                  Working...