Table remains locked after exiting script

This is a discussion on Table remains locked after exiting script within the MySQL Database forums, part of the Database Forums category; Hi all, I've been told that when a PHP script exits, then all tables that were locked from within ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-15-2007
Taras_96
 
Posts: n/a
Default Table remains locked after exiting script

Hi all,

I've been told that when a PHP script exits, then all tables that were
locked from within the PHP script are unlocked.. obviously this is a
good idea.

However, I'm experiencing a problem in the website that I'm currently
coding; the table doesn't unlock after I exit the script. Below is the
PHP snippet relating to the problem area.

$com->setQuery('LOCK TABLE updates WRITE, documents WRITE');
$com->execute();
$com->reset();

exit();

$com is a reference to an object that we use to build up and execute
queries, and I don't think is that important as it doesn't do anything
special (it's essentially an extra layer we've added to ensure that
any strings that are used in the query are properly escaped).

The user that is used in executing this query is called
'lockedDocManip'. When the Server connections are viewed in MySQL
Admin, this user has a connection after exit() is called because
persistent connections are being used. After running the PHP script
above, I've clicked the 'home' link, which uses SQL to check that the
user is currently logged in (an SQL user called 'login').

This new connection that is established is in a 'locked' state when
viewed in Mysql Admin, which confirms that the tables are still
locked.

What could be causing this problem?

The reason why I'm using locks is that a field exists that multiple
users can edit, but it can not be re-edited once it has been edited
once. I thus lock the tables, see if anyone has edited the field, and
if not, edit it. If I don't lock the tables a race condition occurs.
Is there perhaps an alternative solution to this problem?

Thanks

Taras

Reply With Quote
  #2 (permalink)  
Old 03-15-2007
Captain Paralytic
 
Posts: n/a
Default Re: Table remains locked after exiting script

On 15 Mar, 11:42, "Taras_96" <taras...@gmail.com> wrote:
> Hi all,
>
> I've been told that when a PHP script exits, then all tables that were
> locked from within the PHP script are unlocked.. obviously this is a
> good idea.
>
> However, I'm experiencing a problem in the website that I'm currently
> coding; the table doesn't unlock after I exit the script. Below is the
> PHP snippet relating to the problem area.
>
> $com->setQuery('LOCK TABLE updates WRITE, documents WRITE');
> $com->execute();
> $com->reset();
>
> exit();
>
> $com is a reference to an object that we use to build up and execute
> queries, and I don't think is that important as it doesn't do anything
> special (it's essentially an extra layer we've added to ensure that
> any strings that are used in the query are properly escaped).
>
> The user that is used in executing this query is called
> 'lockedDocManip'. When the Server connections are viewed in MySQL
> Admin, this user has a connection after exit() is called because
> persistent connections are being used. After running the PHP script
> above, I've clicked the 'home' link, which uses SQL to check that the
> user is currently logged in (an SQL user called 'login').
>
> This new connection that is established is in a 'locked' state when
> viewed in Mysql Admin, which confirms that the tables are still
> locked.
>
> What could be causing this problem?
>
> The reason why I'm using locks is that a field exists that multiple
> users can edit, but it can not be re-edited once it has been edited
> once. I thus lock the tables, see if anyone has edited the field, and
> if not, edit it. If I don't lock the tables a race condition occurs.
> Is there perhaps an alternative solution to this problem?
>
> Thanks
>
> Taras


How about not using persistant connections and/or issuing a and UNLOCK
TABLES command?

Reply With Quote
  #3 (permalink)  
Old 03-15-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Table remains locked after exiting script

Taras_96 wrote:
> Hi all,
>
> I've been told that when a PHP script exits, then all tables that were
> locked from within the PHP script are unlocked.. obviously this is a
> good idea.
>
> However, I'm experiencing a problem in the website that I'm currently
> coding; the table doesn't unlock after I exit the script. Below is the
> PHP snippet relating to the problem area.
>
> $com->setQuery('LOCK TABLE updates WRITE, documents WRITE');
> $com->execute();
> $com->reset();
>
> exit();
>
> $com is a reference to an object that we use to build up and execute
> queries, and I don't think is that important as it doesn't do anything
> special (it's essentially an extra layer we've added to ensure that
> any strings that are used in the query are properly escaped).
>
> The user that is used in executing this query is called
> 'lockedDocManip'. When the Server connections are viewed in MySQL
> Admin, this user has a connection after exit() is called because
> persistent connections are being used. After running the PHP script
> above, I've clicked the 'home' link, which uses SQL to check that the
> user is currently logged in (an SQL user called 'login').
>
> This new connection that is established is in a 'locked' state when
> viewed in Mysql Admin, which confirms that the tables are still
> locked.
>
> What could be causing this problem?
>
> The reason why I'm using locks is that a field exists that multiple
> users can edit, but it can not be re-edited once it has been edited
> once. I thus lock the tables, see if anyone has edited the field, and
> if not, edit it. If I don't lock the tables a race condition occurs.
> Is there perhaps an alternative solution to this problem?
>
> Thanks
>
> Taras
>


Why in the world would you use persistent connections?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:20 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0