Linux/PHP question

John Abreau abreauj-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Mon Nov 3 20:54:47 EST 2008


It's hard to tell without any information of what "not working" means.

One obvious problem is that you don't allow for the possibility
that two or more instances could try to update the counter file
at the same time.

 Let's say you get 10 hits at roughly the same time, such that
all 10 read the file before any of them write to the file. The last
one to write the file increments the count by 1, and so the count
only goes up by 1 even though there were actually 10 hits.





On Mon, Nov 3, 2008 at 2:53 PM, Myrle Francis <mafmanet-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
> HI,
>
>  I created a simple counter for my website and it doesn't seem to be
> working. I copied it from a windows/apache installation on my local windows
> machine and it works there (just not on linux)
>
> The file that contains the hit count hitcount.txt has the attributeof rw-
> rw- rw.
>
> The program itself counter.php has the attribute of rwx r-x r-x
>
> The  code is as followes:
> <?php
> $count_my_page = ("hitcounter.txt");
> $hits = file($count_my_page);
> $hits[0] ++;
> $fp = fopen($count_my_page , "w");
> fputs($fp , "$hits[0]");
> fclose($fp);
> echo $hits[0];
> ?>
>
> could anyone please provide me with a clue as to what i'm doing wrong.
> I've written another simple pnp programs on this site (rootshell.be) and I
> know php works.
>
>
> Thank you
> Myrle
>
>
> --
> --
> Myrle A. Francis 2nd
>
> PgpServer(s): pgp.mit.edu
>
> Type bits /keyID    Date       User ID
> pub  1024D/30BDB814 2006/07/27 Myrle A. Francis 2nd <mafmanet-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org>
>    Key fingerprint = 73E3 6EAF EC29 29A3 94F9  6C78 F427 0FE8 30BD B814
> _______________________________________________
> Discuss mailing list
> Discuss-mNDKBlG2WHs at public.gmane.org
> http://lists.blu.org/mailman/listinfo/discuss
>



-- 
John Abreau / Executive Director, Boston Linux & Unix
GnuPG KeyID: 0xD5C7B5D9 / Email: abreauj-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
GnuPG FP: 72 FB 39 4F 3C 3B D6 5B E0 C8 5A 6E F1 2C BE 99





More information about the Discuss mailing list