Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Mar 2011 19:11:15 +0100
From:      =?utf-8?B?RnLDqWTDqXJpYw==?= Perrin  <fred@resel.fr>
To:        freebsd-questions@freebsd.org
Subject:   Re: why does this simple counter fail?
Message-ID:  <kggr59xpv0c.fsf@pc-df-302.priv.enst-bretagne.fr>
References:  <20110323164504.GA25317@thought.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Gary Kline <kline@thought.org> writes:
> 	Can any of you php hackers tell me why this simple self-hacked
> 	counter bomb?

As others said, what does 'this simple counter bomb' means?

        > $fp = fopen($directory.$file, "r+");
        > flock($fp, 1);

You want an exclusive lock (LOCK_EX, which is 2 is you use some ancient
PHP), not a shared lock.

When updating the file:
	> fputs($fp, $count);
	> fputs($fp, "\n");
        > fputs($fp, $file);

Why do you feel the need to store the filename inside the file itself?
You don't seem to need it after.

-- 
Frédéric Perrin -- http://tar-jx.bz




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?kggr59xpv0c.fsf>