From owner-freebsd-questions@FreeBSD.ORG Fri Mar 25 16:47:21 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 973781065672 for ; Fri, 25 Mar 2011 16:47:21 +0000 (UTC) (envelope-from editor@d3photography.com) Received: from server.cwis.biz (70-89-202-5-invergrove-mn.hfc.comcastbusiness.net [70.89.202.5]) by mx1.freebsd.org (Postfix) with ESMTP id 67D818FC15 for ; Fri, 25 Mar 2011 16:47:21 +0000 (UTC) Received: from server.cwis.biz (localhost [127.0.0.1]) by server.cwis.biz (Postfix) with ESMTP id 01FF82639F7E for ; Fri, 25 Mar 2011 11:47:50 -0500 (CDT) X-Virus-Scanned: amavisd-new at cwis.biz Received: from server.cwis.biz ([127.0.0.1]) by server.cwis.biz (server.cwis.biz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id R580R1cTT5Jr for ; Fri, 25 Mar 2011 11:47:37 -0500 (CDT) Received: from [192.168.46.85] (unknown [64.122.64.171]) by server.cwis.biz (Postfix) with ESMTPSA id AB8642639F7C for ; Fri, 25 Mar 2011 11:47:36 -0500 (CDT) Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Apple Message framework v1082) From: Ryan Coleman In-Reply-To: <20110325164445.GA16901@thought.org> Date: Fri, 25 Mar 2011 11:47:04 -0500 Content-Transfer-Encoding: quoted-printable Message-Id: <12F2AE40-58EE-455D-91B8-608A3925674F@d3photography.com> References: <20110323164504.GA25317@thought.org> <20110324230049.GB31958@thought.org> <89898D0E-B4A9-41E9-B829-DF7CA8D3FF06@d3photography.com> <20110325053630.GA6722@thought.org> <20110325164445.GA16901@thought.org> To: FreeBSD Mailing List X-Mailer: Apple Mail (2.1082) 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: Fri, 25 Mar 2011 16:47:21 -0000 That would cause a lot of file hanging, with locking, if you get any = decent amount of traffic...=20 I'd just stick to the simple TXT counter for the time being. If you did a mass file, your best bet would be to use arrays and = serialize the data... but that's a lesson for another day. On Mar 25, 2011, at 11:44 AM, Gary Kline wrote: > On Fri, Mar 25, 2011 at 06:36:34AM -0500, Ryan Coleman wrote: >> You're using a completely stock php.ini file. >>=20 >> Look for short tags. Turn that on. >>=20 >> >=20 >> I don't see why you need the file name in the file itself... just = have a number there. Much faster on the CPU. >=20 >=20 > True enough. I could have everything in one file and simply > print the filename and number. I didn't know that I had the=20 > option of using short flags or not. Where do I set that? (I'm=20= > sure there are more places where i have "" rather=20 > than ""; be nice to _not_ have this cause me grief=20= > again....) >=20 > tx, >=20 > gary >=20 >=20 >>=20 >> -- >> Ryan >>=20 >> On Mar 25, 2011, at 12:36 AM, Gary Kline wrote: >>=20 >>> On Thu, Mar 24, 2011 at 06:25:39PM -0500, Ryan Coleman wrote: >>>> Gary, you missed the put... fput($fp, $file); means you're dropping = the filename INTO the storage file. >>>=20 >>>=20 >>> okay. [maybe]. i think what the script does is create >>> ./countdir/$file ; in this case, ./countdir/index where i create >>> the file named "index\n" and below it the integer count. e.g.: >>>=20 >>> in directory countdir, in file index is: >>>=20 >>> index >>> 60311 >>>=20 >>> to track the hits for my homepage. in defense of this crude >>> hack with no error-checking is that i have used the same script >>> in at least three other virtual thought.org websites. =20 >>>=20 >>> i was wrong is saying that the script bombed; it just failed; >>> the reason was that the initial tag had been ">> ">>=20 >>> gary >>>=20 >>>=20 >>>>=20 >>>>=20 >>>> On Mar 24, 2011, at 6:00 PM, Gary Kline wrote: >>>>=20 >>>>> On Wed, Mar 23, 2011 at 07:11:15PM +0100, Fr?d?ric Perrin wrote: >>>>>> Gary Kline writes: >>>>>>> Can any of you php hackers tell me why this simple = self-hacked >>>>>>> counter bomb? >>>>>>=20 >>>>>> As others said, what does 'this simple counter bomb' means? >>>>>>=20 >>>>>>> $fp =3D fopen($directory.$file, "r+"); >>>>>>> flock($fp, 1); >>>>>>=20 >>>>>> You want an exclusive lock (LOCK_EX, which is 2 is you use some = ancient >>>>>> PHP), not a shared lock. >>>>>>=20 >>>>>> When updating the file: >>>>>> > fputs($fp, $count); >>>>>> > fputs($fp, "\n"); >>>>>>> fputs($fp, $file); >>>>>>=20 >>>>>> Why do you feel the need to store the filename inside the file = itself? >>>>>> You don't seem to need it after. >>>>>=20 >>>>>=20 >>>>> $file is passed from the calling php file. index.php is by-hand >>>>> set to >>>>>=20 >>>>> $file=3D'index';=20 >>>>>=20 >>>>> and so on. =20 >>>>>=20 >>>>> Because of my shoulder/typing woes, it was great that I got = clued in >>>>> above by Brad's thought that perhaos there were mis-matched ">>>> and "?>" tags. A simply recursive grepping found out that it = some=20 >>>>> places I had " instead of " . Adding the = "php"=20 >>>>> fixed everything. =20 >>>>>=20 >>>>> Finally, you're right; this really, really is ancient php. >>>>> Somthing i found pre-2004 and hacked until it worked. The >>>>> counter is missings lots of features, but I'll fix that pretty >>>>> soon. >>>>>=20 >>>>> thanks to everybody , >>>>>=20 >>>>>=20 >>>>>>=20 >>>>>> --=20 >>>>>> Fr=E9d=E9ric Perrin -- http://tar-jx.bz >>>>>>=20 >>>>>> _______________________________________________ >>>>>> freebsd-questions@freebsd.org mailing list >>>>>> http://lists.freebsd.org/mailman/listinfo/freebsd-questions >>>>>> To unsubscribe, send any mail to = "freebsd-questions-unsubscribe@freebsd.org" >>>>>=20 >>>>> --=20 >>>>> Gary Kline kline@thought.org http://www.thought.org Public = Service Unix >>>>> Journey Toward the Dawn, E-Book: http://www.thought.org >>>>> The 7.98a release of Jottings: http://jottings.thought.org >>>>>=20 >>>>> _______________________________________________ >>>>> freebsd-questions@freebsd.org mailing list >>>>> http://lists.freebsd.org/mailman/listinfo/freebsd-questions >>>>> To unsubscribe, send any mail to = "freebsd-questions-unsubscribe@freebsd.org" >>>>=20 >>>>=20 >>>=20 >>> --=20 >>> Gary Kline kline@thought.org http://www.thought.org Public = Service Unix >>> Journey Toward the Dawn, E-Book: http://www.thought.org >>> The 7.98a release of Jottings: http://jottings.thought.org >>>=20 >>> _______________________________________________ >>> freebsd-questions@freebsd.org mailing list >>> http://lists.freebsd.org/mailman/listinfo/freebsd-questions >>> To unsubscribe, send any mail to = "freebsd-questions-unsubscribe@freebsd.org" >>=20 >>=20 >=20 > --=20 > Gary Kline kline@thought.org http://www.thought.org Public Service = Unix > Journey Toward the Dawn, E-Book: http://www.thought.org > The 7.98a release of Jottings: http://jottings.thought.org >=20