Fopen problems

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

    #1

    Fopen problems

    I'm trying to fopen a file this way:

    $handle = fopen("http://localhost/test.html", "r");

    but tha page remains "loading .." for 30 seconds and then goes in
    timeout.

    However I can open that file this way:

    $handle = fopen("c:\web\t est.html", "r");

    What is the difference and how can I make the first instruction to
    work?

    Best regards.

    F.
  • Captain Paralytic

    #2
    Re: Fopen problems

    On 23 May, 11:35, joker197cinque <joker197cin... @gmail.comwrote :
    I'm trying to fopen a file this way:
    >
    $handle = fopen("http://localhost/test.html", "r");
    >
    but tha page remains "loading .." for 30 seconds and then goes in
    timeout.
    >
    However I can open that file this way:
    >
    $handle = fopen("c:\web\t est.html", "r");
    >
    What is the difference and how can I make the first instruction to
    work?
    >
    Best regards.
    >
    F.
    What happens if you just put http://localhost/test.html in your
    browser address bar?
    Does the page display?

    Comment

    • Captain Paralytic

      #3
      Re: Fopen problems

      On 23 May, 11:35, joker197cinque <joker197cin... @gmail.comwrote :
      I'm trying to fopen a file this way:
      >
      $handle = fopen("http://localhost/test.html", "r");
      >
      but tha page remains "loading .." for 30 seconds and then goes in
      timeout.
      >
      However I can open that file this way:
      >
      $handle = fopen("c:\web\t est.html", "r");
      >
      What is the difference and how can I make the first instruction to
      work?
      >
      Best regards.
      >
      F.
      Also have you read the manual on fopen?

      where it says:
      If PHP has decided that filename specifies a registered protocol, and
      that protocol is registered as a network URL, PHP will check to make
      sure that allow_url_fopen is enabled. If it is switched off, PHP will
      emit a warning and the fopen call will fail.

      Have you got warning messages enabled?

      Comment

      • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

        #4
        Re: Fopen problems

        joker197cinque escribió:
        $handle = fopen("http://localhost/test.html", "r");
        >
        but tha page remains "loading .." for 30 seconds and then goes in
        timeout.
        >
        However I can open that file this way:
        >
        $handle = fopen("c:\web\t est.html", "r");
        >
        What is the difference and how can I make the first instruction to
        work?
        http://localhost/test.html is a web site and c:\web\test.htm l is a file
        in your hard disc.

        Do you really need to load a file from a third-party web server? I'm
        almost sure that a simple fopen('test.htm l', 'r') will do for you.



        --
        -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
        -- Mi sitio sobre programación web: http://bits.demogracia.com
        -- Mi web de humor al baño María: http://www.demogracia.com
        --

        Comment

        • joker197cinque

          #5
          Re: Fopen problems

          On 23 Mag, 12:55, Captain Paralytic <paul_laut...@y ahoo.comwrote:
          Have you got warning messages enabled?
          If I browse that URL via browser it works.

          If I add error_reporting ALL I obtain:

          [function.fopen]: failed to open stream: A connection attempt failed
          because the connected party did not properly respond after a period of
          time, or established connection failed because connected host has
          failed to respond. in C:\AppServ\www\ go.php on line 4

          Fatal error: Maximum execution time of 30 seconds exceeded in C:
          \AppServ\www\go .php on line 4

          Any help appreciated.

          Comment

          • joker197cinque

            #6
            Re: Fopen problems

            On 23 Mag, 13:06, "Álvaro G. Vicario"
            <alvaroNOSPAMTH A...@demogracia .comwrote:
            Do you really need to load a file from a third-party web server? I'm
            almost sure that a simple fopen('test.htm l', 'r') will do for you.
            I tried with relative path too...with no luck

            Comment

            • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

              #7
              Re: Fopen problems

              joker197cinque escribió:
              On 23 Mag, 13:06, "Álvaro G. Vicario"
              <alvaroNOSPAMTH A...@demogracia .comwrote:
              >
              >Do you really need to load a file from a third-party web server? I'm
              >almost sure that a simple fopen('test.htm l', 'r') will do for you.
              >
              I tried with relative path too...with no luck
              Do you have a specific need? Coding randomly will eventually produce
              something that runs without errors or timeouts but... will it solve your
              problem?


              --
              -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
              -- Mi sitio sobre programación web: http://bits.demogracia.com
              -- Mi web de humor al baño María: http://www.demogracia.com
              --

              Comment

              • Captain Paralytic

                #8
                Re: Fopen problems

                On 23 May, 12:06, "Álvaro G. Vicario"
                <alvaroNOSPAMTH A...@demogracia .comwrote:
                Do you really need to load a file from a third-party web server? I'm
                almost sure that a simple fopen('test.htm l', 'r') will do for you.
                >
                He already said in the OP:
                However I can open that file this way:

                $handle = fopen("c:\web\t est.html", "r");

                Comment

                • joker197cinque

                  #9
                  Re: Fopen problems

                  On 23 Mag, 13:48, "Álvaro G. Vicario"
                  <alvaroNOSPAMTH A...@demogracia .comwrote:
                  joker197cinque escribió:
                  >
                  On 23 Mag, 13:06, "Álvaro G. Vicario"
                  <alvaroNOSPAMTH A...@demogracia .comwrote:
                  >
                  Do you really need to load a file from a third-party web server? I'm
                  almost sure that a simple fopen('test.htm l', 'r') will do for you.
                  >
                  I tried with relative path too...with no luck
                  >
                  Do you have a specific need?
                  I would only open a local url from a php page.
                  Coding randomly will eventually produce
                  something that runs without errors or timeouts but... will it solve your
                  problem?
                  I didn't understand.

                  Comment

                  • joker197cinque

                    #10
                    Re: Fopen problems

                    If I open url this way:

                    fopen("test.htm l", "r") from my go.php page it works.

                    I now have to pass some vars to this page:

                    fopen("test.htm l?var1=test&var 2=test", "r");

                    but this does not work.

                    Which is the correct way?

                    Best regards.

                    Comment

                    • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

                      #11
                      Re: Fopen problems

                      joker197cinque escribió:
                      If I open url this way:
                      >
                      fopen("test.htm l", "r") from my go.php page it works.
                      >
                      I now have to pass some vars to this page:
                      >
                      fopen("test.htm l?var1=test&var 2=test", "r");
                      >
                      but this does not work.
                      >
                      Which is the correct way?
                      You mean this?

                      ::: go.php

                      <?php
                      $var1 = 'test';
                      $var2 = 'test';
                      require('test.h tml');
                      ?>

                      ::: test.html

                      <?php
                      print "Hello $var1 and $var2\n";
                      ?>



                      --
                      -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
                      -- Mi sitio sobre programación web: http://bits.demogracia.com
                      -- Mi web de humor al baño María: http://www.demogracia.com
                      --

                      Comment

                      • joker197cinque

                        #12
                        Re: Fopen problems

                        On 23 Mag, 14:27, "Álvaro G. Vicario"
                        <alvaroNOSPAMTH A...@demogracia .comwrote:
                        You mean this?
                        [CUT]

                        No, I mean to fopen (or whatelse function) a simple URL that should
                        contain some stuff in querystring (search.php?q=s tuff) as when I try
                        to do this:

                        fopen("test.htm l?var1=test&var 2=test", "r");

                        it does not work.

                        Any help?

                        Regards.

                        Comment

                        • sheldonlg

                          #13
                          Re: Fopen problems

                          joker197cinque wrote:
                          On 23 Mag, 14:27, "Álvaro G. Vicario"
                          <alvaroNOSPAMTH A...@demogracia .comwrote:
                          >
                          >You mean this?
                          >
                          [CUT]
                          >
                          No, I mean to fopen (or whatelse function) a simple URL that should
                          contain some stuff in querystring (search.php?q=s tuff) as when I try
                          to do this:
                          >
                          fopen("test.htm l?var1=test&var 2=test", "r");
                          >
                          it does not work.
                          >
                          Any help?
                          >
                          Regards.
                          What do **YOU** mean by open? You seem to be flipping between two
                          things. On the one hand you seem to want to open something (a file) so
                          that can read in its contents and do something with it. On the other
                          hand, you seem to simply want to "open" a web page, aka displaying it,
                          with passed in parameters. Can you explain exactly what you are trying
                          to do? That is, what is your larger problem?

                          Comment

                          • Michael Fesser

                            #14
                            Re: Fopen problems

                            ..oO(joker197ci nque)
                            >On 23 Mag, 14:27, "Álvaro G. Vicario"
                            ><alvaroNOSPAMT HA...@demograci a.comwrote:
                            >
                            >You mean this?
                            >
                            >[CUT]
                            >
                            >No, I mean to fopen (or whatelse function) a simple URL that should
                            >contain some stuff in querystring (search.php?q=s tuff) as when I try
                            >to do this:
                            Yes, but if the requested file is on the same machine, you can use other
                            ways to include it and pass values to it, as shown in Álvaro's example.
                            Might require some changes in the code, though.
                            >fopen("test.ht ml?var1=test&va r2=test", "r");
                            >
                            >it does not work.
                            >
                            >Any help?
                            Just to summarize:

                            * opening test.html directly on disk with fopen()
                            -works

                            * calling http://localhost/test.html?var1=test&var2=test in the browser
                            -works

                            * opening http://localhost/test.html?var1=test&var2=test with fopen()
                            -fails

                            Correct?

                            Can you open other external URLs with fopen() or file_get_conten ts()?
                            Does something appear in the server's logfiles? Does this all happen on
                            a single machine or is the web server running on another machine than
                            the browser for example?

                            Micha

                            Comment

                            • Michael Fesser

                              #15
                              Re: Fopen problems

                              ..oO(sheldonlg)
                              >What do **YOU** mean by open? You seem to be flipping between two
                              >things. On the one hand you seem to want to open something (a file) so
                              >that can read in its contents and do something with it. On the other
                              >hand, you seem to simply want to "open" a web page, aka displaying it,
                              Opening a web page with fopen() doesn't necessarily mean that it's
                              intended for displaying it. You pass some variables to an external
                              script via HTTP, get the results back and then do something with it.
                              But for the OP this call fails for some unknown reason.

                              Micha

                              Comment

                              Working...