funny problem

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

    funny problem

    Hi,
    (1) I have about 8-9 .php files which are far from complex. I first
    used GET in all of them. Worked fine. Then I changed all method="get"
    to method="post" and $_GET to $_POST with search-replace, thinking that
    it should work, but, it seems the $_POST variables are not getting
    populated. Then I tried a simple one-page script using post - works
    fine. So what could be the problem? I am not using
    import_request_ variables() or any such advanced feature.


    (2) How do you address the situation where you have several
    simultaneous users of your web application and your script reads from
    the same single file, and maybe writes to the same single file(keep
    aside the case of poor design, I am talking of say a page hit counter,
    or reading initial settings from the single file), will not several
    copies of your code in memory reading the same file on disk cause
    problems? is there some specific code for such a situation? I looked
    for "threadsafe " and "multiple user" but could not get anything.

    Any help is appreciated.
    Joseph S.

  • Tomasz Wysocki

    #2
    Re: funny problem

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Joseph S. napisa³(a):[color=blue]
    > Hi,
    > (1) I have about 8-9 .php files which are far from complex. I first
    > used GET in all of them. Worked fine. Then I changed all method="get"
    > to method="post" and $_GET to $_POST with search-replace, thinking that
    > it should work, but, it seems the $_POST variables are not getting
    > populated. Then I tried a simple one-page script using post - works
    > fine. So what could be the problem? I am not using
    > import_request_ variables() or any such advanced feature.[/color]

    Maybe you using something like:

    echo "<a href=\"index?a= $a\">text</a>";

    This is works only with $_GET.

    Tom Wysocki
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.1 (GNU/Linux)

    iD8DBQFDYTbOLaR VEfZTNaERAs59AJ 9lWhreocKG3wTuU dqFIJzObB0bFACc Cu8D
    IHtXYxGa5wywG5G H0aB2LV4=
    =UOBG
    -----END PGP SIGNATURE-----

    Comment

    • Dikkie Dik

      #3
      Re: funny problem

      Joseph S. wrote:[color=blue]
      > Hi,
      > (1) I have about 8-9 .php files which are far from complex. I first
      > used GET in all of them. Worked fine. Then I changed all method="get"
      > to method="post" and $_GET to $_POST with search-replace, thinking that
      > it should work, but, it seems the $_POST variables are not getting
      > populated. Then I tried a simple one-page script using post - works
      > fine. So what could be the problem? I am not using
      > import_request_ variables() or any such advanced feature.[/color]

      Do you submit the forms or do you build up a query portion of a URL? The
      post method needs a <FORM> tag with form elements. It should be
      submitted. With the get method, you can just call a URL with a query
      portion.
      [color=blue]
      > (2) How do you address the situation where you have several
      > simultaneous users of your web application and your script reads from
      > the same single file, and maybe writes to the same single file(keep
      > aside the case of poor design, I am talking of say a page hit counter,
      > or reading initial settings from the single file), will not several
      > copies of your code in memory reading the same file on disk cause
      > problems? is there some specific code for such a situation? I looked
      > for "threadsafe " and "multiple user" but could not get anything.
      >
      > Any help is appreciated.
      > Joseph S.
      >[/color]
      There are database servers that have addressed the locking and
      multi-user problems for you and there are also free webcounters
      available on the web. But if you want to do it with a file, you could
      try to achieve a file lock. Depending on the OS, you could either
      directly lock the file or work with a separate lockfile. Both have the
      disadvantage that if anything goes wrong, the counter file remains
      locked until you unlock it by hand.
      An alternative approach is to run an external application (by using COM
      on Windows, for example) that is the only process to touch the file.
      Your PHP scripts can then call the external application for both reading
      and writing.

      Best regards

      Comment

      • NC

        #4
        Re: funny problem

        Joseph S. wrote:[color=blue]
        >
        > (1) I have about 8-9 .php files which are far from complex. I first
        > used GET in all of them. Worked fine. Then I changed all method="get"
        > to method="post" and $_GET to $_POST with search-replace, thinking that
        > it should work, but, it seems the $_POST variables are not getting
        > populated. Then I tried a simple one-page script using post - works
        > fine. So what could be the problem?[/color]

        Some typo somewhere... Say, you now have $POST or $_POTS instead of
        $_POST...
        [color=blue]
        > (2) How do you address the situation where you have several
        > simultaneous users of your web application and your script reads from
        > the same single file, and maybe writes to the same single file[/color]

        Reading from the same file on a modern operating system should
        require no attention at all; it is handled on the OS level.
        Writing... well, read up on flock() and see what the manual has
        to say about OS-specific details...


        [color=blue]
        > I looked for "threadsafe " and "multiple user" but could not get
        > anything.[/color]

        Thread is a Windows-only concept. On Unix, there are no threads,
        only full-blown processes, each with a distinct ID... This is
        why file locking would work on Unix, but not on Windows...

        Cheers,
        NC

        Comment

        • Iván Sánchez Ortega

          #5
          Re: funny problem

          -----BEGIN PGP SIGNED MESSAGE-----
          Hash: SHA1

          Joseph S. wrote:
          [color=blue]
          > (2) How do you address the situation where you have several
          > simultaneous users of your web application and your script reads from
          > the same single file, and maybe writes to the same single file[/color]

          Seems like the same old reader-writer concurrency problem. Use some method
          to lock the files, in order to avoid multiple writes. See php.net/flock .

          - --
          - ----------------------------------
          Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

          Los verdaderos programadores no trabajan de 9 a 6. Si puede verse alguno a
          las 9, es porque ha estado toda la noche trabajando.
          -----BEGIN PGP SIGNATURE-----
          Version: GnuPG v1.4.2 (GNU/Linux)

          iD8DBQFDYTtP3jc Q2mg3Pc8RAjzpAK CIAnoVaMG/4ts3A20nacU4+Y9 HzgCcCuM+
          OkDdOCk0seC5EJ0 6bg1ioyI=
          =tZN0
          -----END PGP SIGNATURE-----

          Comment

          • theshz

            #6
            Re: funny problem

            Why not use $_REQUEST?

            Comment

            • Joseph S.

              #7
              Re: funny problem

              Hi,
              It was not typos or urls with "name.php?q=wha tever", it was the form
              tag attribute enctype="text/plain" -
              it was inserted by default in the form tag that is generated by
              PHPEclipse
              when you select the form option for post from the popup dropdown:

              <form action="link" method="post" enctype="text/plain">
              cursor
              </form>

              It does not work with POST but works with GET.
              (which is why the fact that it is part of the default text for the form
              post tag in PHPEclipse comes as a surprise - it does not work - I have
              XAMPP installed Apache/2.0.54 PHP/5.0.4 )

              What I found is that with post, the enctype attribute
              must either be omitted completely:
              <form action="myform. php" method="post">
              </form>
              or,
              if specified, must be set to
              enctype="applic ation/x-www-form-urlencoded" or
              enctype="mulitp art/form-data"
              which work.

              As for concurrent file access, as Dikkie pointed out,
              it is better to use a database
              and if only read is involved, the OS should takes care of it.

              I read php.net/flock and it seems better to use a database, however
              small.

              Thanks all,
              Regards,
              Joseph.

              Comment

              Working...