RE: [PHP] incrementing a number from a text file
Is it possible to let the OS handle the collisions? For example: $last_value = system('cat counter.txt', $retval); $last_value++; $result = system('echo $last_value > counter.txt', $retval); ...just a suggestion! Regards /Luis -Original Message- From: Richard Lynch [mailto:[EMAIL PROTECTED] Sent: Thursday, March 10, 2005 3:14 PM To: Ross Hulford Cc: php-general@lists.php.net Subject: Re: [PHP] incrementing a number from a text file > I want to read a number from an external (txt) file and increment > it.then save the number back on the text file. > I know this is possible but want a simple amd economical way to do this. That's what you *THINK* you want to do :-) But what happens when *TWO* users hit that same script at exactly the same time. At best, you get: User1 User2 Reads 9 Reads 9 Writes 10 Writes 10 and when you should have 11, you've only got 10. [aside] "My amp goes to 11!" [/aside] But it's worse than that: It's entirely poassible that your script, instead of having two users write "10" one after the other, will have two users both trying to write "10" at EXACTLY the same time. The result is comparable to a head-on collision between two trains. Your file is TOAST. This is why so many early "hit counter" scripts back in the day were always getting messed up and reset to 0. What you really want, almost for sure, is an SQL database with "sequences" You have to forge those in MySQL by making a table with auto_increment. You *can* use http://php.net/flock, but even that is a Bad Idea, because flock under Un*x is self-imposed -- If some *other* program/script/user decides not change that file and doesn't use flock, well, they're not STOPPED from doing that. flock is therefore all too subject to human fallibility when you re-work, re-write, or add more code to your system. The SQL guys have worked out this problem, in all respects. This is one of those things that SEEMS so simple that turns out to be a hell of a lot more involved than you thought at first. So it goes. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] software catalog
Well... I see in HotScripts that there is a category named "E-Commerce" and inside there is a sub-category named "Shopping Carts"... [ http://www.hotscripts.com/PHP/Scripts_and_Programs/E-Commerce/Shopping_C arts/index.html ] Good Luck! /Luis -Original Message- From: Ryan A [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 09, 2005 5:51 PM To: [EMAIL PROTECTED] Cc: php Subject: Re: [PHP] software catalog Hey! Thanks for replying. Hot scripts and script search ware the two places which i checked out first before writing to the list, then google, because I dont need a jackass who has been on the list for 2 days telling me to f***ing google for it, just coz it would make him feel happy with himself :-) I dont want to build this from scratch as I am sure there must be quite a few out there, i'm just surprised that nobody has recommended one that they used or heard about other than Chris (from this same list) A very basic cart would do but searching for shopping cart php gives me hundreds of results, its really hard sorting through all that trying to find one that caters to just software selling. I have not checked SF as yet, thanks for the tip, will hit that immd after this email. In the meantime if anything comes to mind please drop me a line. Thanks, Ryan On 3/8/2005 9:12:58 PM, James Williams ([EMAIL PROTECTED]) wrote: > What's up Ryan, I do believe that the cart software you choose should > for the most part be independent upon what exactly your selling. > There are a few big shopping cart solutions that work for selling > anything and I'm sure there are features and / or plugins that will > allow you to do > > discounts based on multiple product purchases. hit up sourceforge or > > hot scipts and you're sure to find plenty of awsome results. Good Luck! > > Ryan A wrote: > > Hey! > > Anybody know of a "software catalog" (or cart preferably) that is free? > > > > A site i am working for sells software, now they want to have a cart feature > > so people can put the packages in a cart and get discounts etc if > > they purchase more than 1 product...they are using 2checkout for processing. > > > > I checked the usual places and google of "php software cart" but got back > > garbled results, most of that carts are for tangible products :-( > > > > Any help or recommendations would be appreciated. > > > > Thanks in advance, > > Ryan > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: > http://www.php.net/unsub.php -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.7.0 - Release Date: 3/8/2005 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php