Locks in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Locks in php

Post by tores »

Hi all

Can anyone tell me an efficient way of implementing locks in php. I want locks to restrict database access from simultaniously running scripts. And I want a lock that I can set in one script and release later in another. With my system configuration beeing windows xp, apache and php running as an module on it, the only solution I could come up with is using files for each db-table and then use flock() to lock each of these files. However this yields bad performance as I have to access a file on each db-query...
I've tried using persistent connections against the mysql-server I'm running, but couldn't get the desired results (I'm pretty sure now that this approach is impossible to use with the current versions of mysql (4.1.19) and php (5.0.3)).

Note: The semaphore extension is not available in Windows....

regards tores
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

in the past (while making applications) we used mutexes, similar to semaphores. If you can get win32 api to set up, you should be able to call the mutex functions, since they are all run under the same process.. for a little more platform independant, you can use your own form of locking in tables (if the database/table type you use does not support locking on it's own)

Note: you may be able to switch the table type to a lockable one.. check the MySQL manual on InnoDB..
Post Reply