PHP Classes

Mysql Locker: Safely manage MySQL table locks

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 743 All time: 4,514 This week: 206Up
Version License Categories
mysqllocker 1.0GNU Lesser Genera...PHP 5, Databases
Description 

Author

This class can safely manage the locking and unlocking of MySQL tables.

The table locks are created when an object of the class is created, and are automatically released when the object is destroyed.

The table unlocking occurs when the object is no longer referenced, or when it goes out of scope. The latter also occurs when a PHP script dies or when an exception occurs. This is where this class is most useful because it will make sure that all existing locks are automatically released even when using persistent connections.

The class takes advantage of PHP 5 class destructor support to make sure that the unlocking of any locked tables always happen.

Innovation Award
PHP Programming Innovation award nominee
February 2005
Number 5


Prize: One copy of the Zend Studio
One of the problems of using database transactions, table locks or other means that grant exclusive access to database resources for a running script, is that when that script ends all locks must be released.

This problem may become critical when the scripts use persistent connections to access the database and the developer forgot to release the locks or the script exited due to an unexpected error.

When the connections are not persistent, at the end of the script the database connection is closed and all locks are implicitly released.

However, when the connection is persistent, the database connection is not closed and the locks remain until the current Web server process is terminated. This situation may lock the whole database access for an indefinite period.

This class provides a solution that uses constructors and destructors functions to establish and release the necessary table locks. Even when a script exits in an unexpected way, the destructor function is always called and any outstanding locks are released.

Manuel Lemos
Picture of Craig Manley
Name: Craig Manley <contact>
Classes: 5 packages by
Country: The Netherlands The Netherlands
Age: ???
All time rank: 2317 in The Netherlands The Netherlands
Week rank: 256 Down9 in The Netherlands The Netherlands Down
Innovation award
Innovation award
Nominee: 4x

  Files folder image Files (2)  
File Role Description
Plain text file MysqlLocker.php Class The only class.
Accessible without login Plain text file t.php Example Test script.

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:743
This week:0
All time:4,514
This week:206Up
User Comments (1)
Excellent
15 years ago (kishore kumar)
70%StarStarStarStar