Re-opening a file

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

    Re-opening a file

    Hi. In my application I do something very simple - I open a file, lock
    it exclusively, write some data to it and close it.

    If I re-open it in the same process (I mean before the script has
    ended) to read the file, I find that the data I have written doesn't
    exist in there. I can't read it back until I run the script again.

    My question follows: WHAT

  • Jerry Stuckle

    #2
    Re: Re-opening a file

    W Marsh wrote:
    Hi. In my application I do something very simple - I open a file, lock
    it exclusively, write some data to it and close it.
    >
    If I re-open it in the same process (I mean before the script has
    ended) to read the file, I find that the data I have written doesn't
    exist in there. I can't read it back until I run the script again.
    >
    My question follows: WHAT
    >
    Sorry, my crystal ball is in the shop. I have no idea what might be
    happening. Maybe if you post your code...

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • W Marsh

      #3
      Re: Re-opening a file

      On 15 Jul, 14:41, Jerry Stuckle <jstuck...@attg lobal.netwrote:
      W Marsh wrote:
      Hi. In my application I do something very simple - I open a file, lock
      it exclusively, write some data to it and close it.
      >
      If I re-open it in the same process (I mean before the script has
      ended) to read the file, I find that the data I have written doesn't
      exist in there. I can't read it back until I run the script again.
      >
      My question follows: WHAT
      >
      Sorry, my crystal ball is in the shop. I have no idea what might be
      happening. Maybe if you post your code...
      >
      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstuck...@attgl obal.net
      =============== ===
      No. For one thing it's private, commercial code, and secondly, I've
      given enough information about the problem.

      I don't appreciate people making sarcastic comments like that. If you
      have no idea about the problem then keep quiet, or if you genuinely
      are missing important details, make a polite request, e.g. "Are you
      doing X between closing and re-opening the file?". I'm not an outlet
      for problems with your insecurities and ego.

      If you really are that unimaginative, then here's some code (using my
      own original description as a design spec, proving my point somewhat):

      define(FILE_NAM E, "somefile.txt") ;

      $dataOrig = array("here", "is", "some", "data", "to", "be",
      "serialized ");

      $file = fopen(FILE_NAME , "w");
      flock($file, LOCK_EX);
      fwrite($file, serialize($data Orig));
      fclose($file);

      $file = fopen(FILE_NAME , "r");
      $dataNew = unserialize(fre ad($file, filesize(FILE_N AME)));

      print_r($dataNe w); // Expected output: Array ( [0] =here [1] =is
      [2] =some [3] =data [4] =to [5] =be [6] =serialized )

      It is not representative of the original code in terms of design or
      error checking, but it does reproduce the problem on the production
      server (no output, due to getting no data in the original file). It
      does however run correctly on a my own web server, which suggests the
      problem is one of configuration that somebody with experience in this
      field could shed some light on, which I would be grateful for.

      Do you see?

      Comment

      • rf

        #4
        Re: Re-opening a file

        "W Marsh" <wayne.marsh@gm ail.comwrote in message
        news:1184507821 .293218.166830@ 57g2000hsv.goog legroups.com...
        On 15 Jul, 14:41, Jerry Stuckle <jstuck...@attg lobal.netwrote:
        >Sorry, my crystal ball is in the shop. I have no idea what might be
        >happening. Maybe if you post your code...
        I don't appreciate people making sarcastic comments like that. If you
        have no idea about the problem then keep quiet, or if you genuinely
        are missing important details, make a polite request, e.g. "Are you
        doing X between closing and re-opening the file?". I'm not an outlet
        for problems with your insecurities and ego.
        You are, however, the one with the broken code that is asking the question.

        --
        Richard.


        Comment

        • W Marsh

          #5
          Re: Re-opening a file

          On 15 Jul, 15:08, "rf" <r...@invalid.c omwrote:
          "W Marsh" <wayne.ma...@gm ail.comwrote in message
          >
          news:1184507821 .293218.166830@ 57g2000hsv.goog legroups.com...
          >
          On 15 Jul, 14:41, Jerry Stuckle <jstuck...@attg lobal.netwrote:
          Sorry, my crystal ball is in the shop. I have no idea what might be
          happening. Maybe if you post your code...
          I don't appreciate people making sarcastic comments like that. If you
          have no idea about the problem then keep quiet, or if you genuinely
          are missing important details, make a polite request, e.g. "Are you
          doing X between closing and re-opening the file?". I'm not an outlet
          for problems with your insecurities and ego.
          >
          You are, however, the one with the broken code that is asking the question.
          >
          --
          Richard.
          Ah, so you've seen where the code I've posted is broken. Excellent! I
          am anxious to see you elaborate further on this.

          Comment

          • Rami Elomaa

            #6
            Re: Re-opening a file

            W Marsh kirjoitti:
            On 15 Jul, 14:41, Jerry Stuckle <jstuck...@attg lobal.netwrote:
            >W Marsh wrote:
            >>Hi. In my application I do something very simple - I open a file, lock
            >>it exclusively, write some data to it and close it.
            >>If I re-open it in the same process (I mean before the script has
            >>ended) to read the file, I find that the data I have written doesn't
            >>exist in there. I can't read it back until I run the script again.
            >>My question follows: WHAT
            >Sorry, my crystal ball is in the shop. I have no idea what might be
            >happening. Maybe if you post your code...
            >>
            >--
            >============== ====
            >Remove the "x" from my email address
            >Jerry Stuckle
            >JDS Computer Training Corp.
            >jstuck...@attg lobal.net
            >============== ====
            >
            No. For one thing it's private, commercial code, and secondly, I've
            given enough information about the problem.
            >
            I don't appreciate people making sarcastic comments like that. If you
            have no idea about the problem then keep quiet, or if you genuinely
            are missing important details, make a polite request, e.g. "Are you
            doing X between closing and re-opening the file?". I'm not an outlet
            for problems with your insecurities and ego.
            >
            If you really are that unimaginative, then here's some code (using my
            own original description as a design spec, proving my point somewhat):
            >
            define(FILE_NAM E, "somefile.txt") ;
            >
            $dataOrig = array("here", "is", "some", "data", "to", "be",
            "serialized ");
            >
            $file = fopen(FILE_NAME , "w");
            flock($file, LOCK_EX);
            fwrite($file, serialize($data Orig));
            fclose($file);
            >
            $file = fopen(FILE_NAME , "r");
            $dataNew = unserialize(fre ad($file, filesize(FILE_N AME)));
            >
            print_r($dataNe w); // Expected output: Array ( [0] =here [1] =is
            [2] =some [3] =data [4] =to [5] =be [6] =serialized )
            >
            It is not representative of the original code in terms of design or
            error checking, but it does reproduce the problem on the production
            server (no output, due to getting no data in the original file). It
            does however run correctly on a my own web server, which suggests the
            problem is one of configuration that somebody with experience in this
            field could shed some light on, which I would be grateful for.
            I'm not sure if you already mentioned this, but if you manuallu open the
            file after running the script, are the values actually written into it,
            on the server where it doesn't work? I mean have you really checked that
            the problem is not in writing to it, but actually reading from it?

            What does
            var_dump( filesize(FILE_N AME) );
            give you?
            Try putting it before the line
            $dataNew = unserialize(fre ad($file, filesize(FILE_N AME)));

            If it yields zero, which might be possible for just created file it
            might be getting it from cache. If this is the case, then running
            clearstatcache( ) ought to solve the problem.

            BTW, I didn't think Jerry's request for code was unreasonable. For
            instance there are many ways for reading from a file. I for one couldn't
            have imagined using fread($file, filesize(FILE_N AME)) for reading, cos I
            always use file_get_conten ts. That's why I think it was good that you
            provided the sample code rather than leave us scraching our heads with
            nothing. When someone asks you for sample code, of course you don't need
            to post the in-house production code, just something that effectively
            reproduces the error.

            --
            Rami.Elomaa@gma il.com

            "Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
            usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

            Comment

            • W Marsh

              #7
              Re: Re-opening a file

              On 15 Jul, 16:53, Rami Elomaa <rami.elo...@gm ail.comwrote:
              W Marsh kirjoitti:
              >
              >
              >
              On 15 Jul, 14:41, Jerry Stuckle <jstuck...@attg lobal.netwrote:
              W Marsh wrote:
              >Hi. In my application I do something very simple - I open a file, lock
              >it exclusively, write some data to it and close it.
              >If I re-open it in the same process (I mean before the script has
              >ended) to read the file, I find that the data I have written doesn't
              >exist in there. I can't read it back until I run the script again.
              >My question follows: WHAT
              Sorry, my crystal ball is in the shop. I have no idea what might be
              happening. Maybe if you post your code...
              >
              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstuck...@attgl obal.net
              =============== ===
              >
              No. For one thing it's private, commercial code, and secondly, I've
              given enough information about the problem.
              >
              I don't appreciate people making sarcastic comments like that. If you
              have no idea about the problem then keep quiet, or if you genuinely
              are missing important details, make a polite request, e.g. "Are you
              doing X between closing and re-opening the file?". I'm not an outlet
              for problems with your insecurities and ego.
              >
              If you really are that unimaginative, then here's some code (using my
              own original description as a design spec, proving my point somewhat):
              >
              define(FILE_NAM E, "somefile.txt") ;
              >
              $dataOrig = array("here", "is", "some", "data", "to", "be",
              "serialized ");
              >
              $file = fopen(FILE_NAME , "w");
              flock($file, LOCK_EX);
              fwrite($file, serialize($data Orig));
              fclose($file);
              >
              $file = fopen(FILE_NAME , "r");
              $dataNew = unserialize(fre ad($file, filesize(FILE_N AME)));
              >
              print_r($dataNe w); // Expected output: Array ( [0] =here [1] =is
              [2] =some [3] =data [4] =to [5] =be [6] =serialized )
              >
              It is not representative of the original code in terms of design or
              error checking, but it does reproduce the problem on the production
              server (no output, due to getting no data in the original file). It
              does however run correctly on a my own web server, which suggests the
              problem is one of configuration that somebody with experience in this
              field could shed some light on, which I would be grateful for.
              >
              I'm not sure if you already mentioned this, but if you manuallu open the
              file after running the script, are the values actually written into it,
              on the server where it doesn't work? I mean have you really checked that
              the problem is not in writing to it, but actually reading from it?
              >
              What does
              var_dump( filesize(FILE_N AME) );
              give you?
              Try putting it before the line
              $dataNew = unserialize(fre ad($file, filesize(FILE_N AME)));
              >
              If it yields zero, which might be possible for just created file it
              might be getting it from cache. If this is the case, then running
              clearstatcache( ) ought to solve the problem.
              Thanks. That seems like a plausible solution. I'll try it at work
              tomorrow.

              I don't think I can use file_get_conten ts in this case, because I want
              to respect file locks. It would be nice if I could get
              file_get_conten ts to do that.
              >
              BTW, I didn't think Jerry's request for code was unreasonable. For
              instance there are many ways for reading from a file. I for one couldn't
              have imagined using fread($file, filesize(FILE_N AME)) for reading, cos I
              always use file_get_conten ts. That's why I think it was good that you
              provided the sample code rather than leave us scraching our heads with
              nothing. When someone asks you for sample code, of course you don't need
              to post the in-house production code, just something that effectively
              reproduces the error.
              It wasn't the request that annoyed me, but the sarcasm. I don't want
              to derail things further by arguing about it though!

              Comment

              • Rami Elomaa

                #8
                Re: Re-opening a file

                "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                news:r8idne2DJ_ tCJQfbnZ2dnUVZ_ gSdnZ2d@comcast .com...
                >W Marsh wrote:
                >On 15 Jul, 15:27, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                >>And BTW - in PHP there is no such thing as "private" code. Once you
                >>give it to a customer the source is available, unless you get one of the
                >>encryption engines, i.e. from Zend.
                >>
                >Well, there is. Not a single person outside of the company will ever
                >see this code, because it's a backend system that powers customer
                >facing front ends. Surely you have come across such a situation
                >before! Not all PHP ends up as forum software.
                >>
                >
                So? That makes it so special? ROFLMAO!
                That makes it _private_. You claimed that no php code is private, because
                the client will always see it. Yet, if the case happens to be that a company
                has it's own IT department that produces software, it will remain private,
                since no second party will have access to it. You ought to be laughing at
                yourself, not to his claim.

                --
                Rami.Elomaa@gma il.com

                "Good tea. Nice house." -- Worf


                Comment

                • Jerry Stuckle

                  #9
                  Re: Re-opening a file

                  Rami Elomaa wrote:
                  "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                  news:r8idne2DJ_ tCJQfbnZ2dnUVZ_ gSdnZ2d@comcast .com...
                  >W Marsh wrote:
                  >>On 15 Jul, 15:27, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                  >>>And BTW - in PHP there is no such thing as "private" code. Once you
                  >>>give it to a customer the source is available, unless you get one of the
                  >>>encryption engines, i.e. from Zend.
                  >>Well, there is. Not a single person outside of the company will ever
                  >>see this code, because it's a backend system that powers customer
                  >>facing front ends. Surely you have come across such a situation
                  >>before! Not all PHP ends up as forum software.
                  >>>
                  >So? That makes it so special? ROFLMAO!
                  >
                  That makes it _private_. You claimed that no php code is private, because
                  the client will always see it. Yet, if the case happens to be that a company
                  has it's own IT department that produces software, it will remain private,
                  since no second party will have access to it. You ought to be laughing at
                  yourself, not to his claim.
                  >
                  Nope, that doesn't make it private. It just means it has restricted
                  access. Different things.

                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: Re-opening a file

                    W Marsh wrote:

                    Oh, and BTW - I didn't even know that you were posting from Google
                    Groups until you mentioned it. That's when I looked at the headers and
                    verified it.

                    And it explains your postings completely.

                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    • C.

                      #11
                      Re: Re-opening a file

                      On 15 Jul, 14:57, W Marsh <wayne.ma...@gm ail.comwrote:
                      On 15 Jul, 14:41, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                      >
                      >
                      >
                      W Marsh wrote:
                      Hi. In my application I do something very simple - I open a file, lock
                      it exclusively, write some data to it and close it.
                      >
                      If I re-open it in the same process (I mean before the script has
                      ended) to read the file, I find that the data I have written doesn't
                      exist in there. I can't read it back until I run the script again.
                      >
                      My question follows: WHAT
                      >
                      Sorry, my crystal ball is in the shop. I have no idea what might be
                      happening. Maybe if you post your code...
                      >
                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstuck...@attgl obal.net
                      =============== ===
                      >
                      No. For one thing it's private, commercial code, and secondly, I've
                      given enough information about the problem.
                      >
                      I don't appreciate people making sarcastic comments like that. If you
                      have no idea about the problem then keep quiet, or if you genuinely
                      are missing important details, make a polite request, e.g. "Are you
                      doing X between closing and re-opening the file?". I'm not an outlet
                      for problems with your insecurities and ego.
                      >
                      If you really are that unimaginative, then here's some code (using my
                      own original description as a design spec, proving my point somewhat):
                      >
                      define(FILE_NAM E, "somefile.txt") ;
                      >
                      $dataOrig = array("here", "is", "some", "data", "to", "be",
                      "serialized ");
                      >
                      $file = fopen(FILE_NAME , "w");
                      flock($file, LOCK_EX);
                      fwrite($file, serialize($data Orig));
                      fclose($file);
                      >
                      $file = fopen(FILE_NAME , "r");
                      $dataNew = unserialize(fre ad($file, filesize(FILE_N AME)));
                      >
                      print_r($dataNe w); // Expected output: Array ( [0] =here [1] =is
                      [2] =some [3] =data [4] =to [5] =be [6] =serialized )
                      >
                      It is not representative of the original code in terms of design or
                      error checking, but it does reproduce the problem on the production
                      server (no output, due to getting no data in the original file). It
                      does however run correctly on a my own web server, which suggests the
                      problem is one of configuration that somebody with experience in this
                      field could shed some light on, which I would be grateful for.
                      >
                      Do you see?

                      AIR filestats are cached therefore filesize() reports the same value
                      after you've changed a file. RTFM for clearstatcache.

                      C.

                      Comment

                      • Brendan Gillatt

                        #12
                        Re: Re-opening a file

                        On Sun, 15 Jul 2007 05:43:20 -0700, W Marsh <wayne.marsh@gm ail.com>
                        wrote:
                        >Hi. In my application I do something very simple - I open a file, lock
                        >it exclusively, write some data to it and close it.
                        >
                        >If I re-open it in the same process (I mean before the script has
                        >ended) to read the file, I find that the data I have written doesn't
                        >exist in there. I can't read it back until I run the script again.
                        >
                        >My question follows: WHAT
                        It works for me okay. Would you post you're code to see what's the
                        problem?
                        --
                        Brendan Gillatt

                        GPG: 0x6E265E61

                        Comment

                        • Rami Elomaa

                          #13
                          Re: Re-opening a file

                          Jerry Stuckle kirjoitti:
                          Rami Elomaa wrote:
                          >"Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                          >news:r8idne2DJ _tCJQfbnZ2dnUVZ _gSdnZ2d@comcas t.com...
                          >>W Marsh wrote:
                          >>>On 15 Jul, 15:27, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                          >>>>And BTW - in PHP there is no such thing as "private" code. Once you
                          >>>>give it to a customer the source is available, unless you get one
                          >>>>of the
                          >>>>encryptio n engines, i.e. from Zend.
                          >>>Well, there is. Not a single person outside of the company will ever
                          >>>see this code, because it's a backend system that powers customer
                          >>>facing front ends. Surely you have come across such a situation
                          >>>before! Not all PHP ends up as forum software.
                          >>>>
                          >>So? That makes it so special? ROFLMAO!
                          >>
                          >That makes it _private_. You claimed that no php code is private,
                          >because the client will always see it. Yet, if the case happens to be
                          >that a company has it's own IT department that produces software, it
                          >will remain private, since no second party will have access to it. You
                          >ought to be laughing at yourself, not to his claim.
                          >>
                          >
                          Nope, that doesn't make it private. It just means it has restricted
                          access. Different things.
                          >
                          Whatever you wanna call it, same difference.

                          --
                          Rami.Elomaa@gma il.com

                          "Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
                          usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

                          Comment

                          • W Marsh

                            #14
                            Re: Re-opening a file

                            On 16 Jul, 12:10, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                            Rami Elomaa wrote:
                            "Jerry Stuckle" <jstuck...@attg lobal.netwrote in message
                            news:r8idne2DJ_ tCJQfbnZ2dnUVZ_ gSdnZ2d@comcast .com...
                            W Marsh wrote:
                            >On 15 Jul, 15:27, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                            >>And BTW - in PHP there is no such thing as "private" code. Once you
                            >>give it to a customer the source is available, unless you get one of the
                            >>encryption engines, i.e. from Zend.
                            >Well, there is. Not a single person outside of the company will ever
                            >see this code, because it's a backend system that powers customer
                            >facing front ends. Surely you have come across such a situation
                            >before! Not all PHP ends up as forum software.
                            >
                            So? That makes it so special? ROFLMAO!
                            >
                            That makes it _private_. You claimed that no php code is private, because
                            the client will always see it. Yet, if the case happens to be that a company
                            has it's own IT department that produces software, it will remain private,
                            since no second party will have access to it. You ought to be laughing at
                            yourself, not to his claim.
                            >
                            Nope, that doesn't make it private. It just means it has restricted
                            access. Different things.
                            Wheeeeee.

                            That's the sound of you moving the goalposts.

                            Comment

                            • Jerry Stuckle

                              #15
                              Re: Re-opening a file

                              W Marsh wrote:
                              >Nope, that doesn't make it private. It just means it has restricted
                              >access. Different things.
                              >
                              Wheeeeee.
                              >
                              That's the sound of you moving the goalposts.
                              >
                              Go play with your code, troll. You obviously don't understand what
                              "private code" is any more than you understand how to ask questions in a
                              newsgroup.

                              --
                              =============== ===
                              Remove the "x" from my email address
                              Jerry Stuckle
                              JDS Computer Training Corp.
                              jstucklex@attgl obal.net
                              =============== ===

                              Comment

                              Working...