Are locks implemented/simulatable in PHP?
Moderator: General Moderators
-
the_drizzle
- Forum Newbie
- Posts: 17
- Joined: Fri Jun 01, 2007 11:55 am
Are locks implemented/simulatable in PHP?
I've been yearning to use locks in PHP for quite some time now, and I always end up finding a context-sensitive workaround. Is there a library somewhere that I can use, or I should I just try to simulate locks? I can imagine solutions by forking processes but I'm running the scripts inside of Apache, and my understanding is that Apache doesn't support forking processes.
Thanks for any help,
Graham
Thanks for any help,
Graham
-
the_drizzle
- Forum Newbie
- Posts: 17
- Joined: Fri Jun 01, 2007 11:55 am
I just want to manipulate a general lock. It's fine if I have to acquire a lock for some crazy thing (i.e. a file) and use that, as long as I can play around with the lock itself. My understanding is that if I can *manually* lock an object like a file, then there should be a generic way to lock anything. In fact, the "file lock" would probably use that generic lock.
So, if I can manually manipulate a lock, then there shouldn't be any difference between a "file lock" and a "database lock" other than context. The difference that your thinking about is probably "locking a file" vs. "locking a database table." In this case, there is no notion of a "lock" to the source code, just a concept of "locking," for example when something writes to the file or database. The actual locks are being used beneath the covers.
Every OS provides lock system calls. I guess I'm looking for the closest thing PHP has that uses such calls.
So, if I can manually manipulate a lock, then there shouldn't be any difference between a "file lock" and a "database lock" other than context. The difference that your thinking about is probably "locking a file" vs. "locking a database table." In this case, there is no notion of a "lock" to the source code, just a concept of "locking," for example when something writes to the file or database. The actual locks are being used beneath the covers.
Every OS provides lock system calls. I guess I'm looking for the closest thing PHP has that uses such calls.
-
the_drizzle
- Forum Newbie
- Posts: 17
- Joined: Fri Jun 01, 2007 11:55 am
http://www.google.ca/url?sa=t&ct=res&cd ... KwI1Lvsjmg
Here's a thing talking about Unix semaphores, which are basically locks but slightly better. Actually, a binary semaphore and a lock are essentially identical.
Now I'm not at all a Unix expert. In fact, my experience with Unix is something very close to zero, so don't quote me on this next bit. I believe that Unix has an internal system that provides general locks to the OS itself, and something like semaphore system calls are just a layer of abstraction between user code and the Unix locks.
Sorry for the initial confusion. I'll try to be more clear with my questions next time.
Thanks for everyone's help.
Here's a thing talking about Unix semaphores, which are basically locks but slightly better. Actually, a binary semaphore and a lock are essentially identical.
Now I'm not at all a Unix expert. In fact, my experience with Unix is something very close to zero, so don't quote me on this next bit. I believe that Unix has an internal system that provides general locks to the OS itself, and something like semaphore system calls are just a layer of abstraction between user code and the Unix locks.
Sorry for the initial confusion. I'll try to be more clear with my questions next time.
Thanks for everyone's help.
I'm not sure what you're looking for. May be http://de2.php.net/sem may be something else.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
-
the_drizzle
- Forum Newbie
- Posts: 17
- Joined: Fri Jun 01, 2007 11:55 am
Yeah, sorry d11, you're right about the multi-threading. I was actually thinking about multiple processes or multiple Apache threads handling several requests simultaneously. So in theory, it may have been possible to share OS locks amongst threads that are responding to different requests. It was my fault for not being clear enough.
Thanks Volka for the link. I just don't understand why I didn't search for "semaphore" in php.net first .... Sometimes it just feels like one of those days.
Thanks Volka for the link. I just don't understand why I didn't search for "semaphore" in php.net first .... Sometimes it just feels like one of those days.