From owner-freebsd-questions@FreeBSD.ORG Wed Mar 23 18:35:09 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1AB131065670 for ; Wed, 23 Mar 2011 18:35:09 +0000 (UTC) (envelope-from freebsd-questions@m.gmane.org) Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mx1.freebsd.org (Postfix) with ESMTP id 420F18FC0C for ; Wed, 23 Mar 2011 18:35:06 +0000 (UTC) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Q2Ste-0007e0-9E for freebsd-questions@freebsd.org; Wed, 23 Mar 2011 19:35:06 +0100 Received: from pool-116.enst-bretagne.fr ([192.108.117.68]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 23 Mar 2011 19:35:06 +0100 Received: from fred by pool-116.enst-bretagne.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 23 Mar 2011 19:35:06 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: freebsd-questions@freebsd.org From: =?utf-8?B?RnLDqWTDqXJpYw==?= Perrin Date: Wed, 23 Mar 2011 19:11:15 +0100 Lines: 22 Message-ID: References: <20110323164504.GA25317@thought.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: pool-116.enst-bretagne.fr User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:75S2ATZYJFWmGwUg91EiKQqqOhM= Subject: Re: why does this simple counter fail? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Mar 2011 18:35:09 -0000 Gary Kline 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