Jump to content

Warning: GET_LOCK and set_time_limit()


kestasjk

Recommended Posts

[code]<?php
set_time_limit(5);
// The script ends if it goes on for 5 secs
mysql_query("SELECT GET_LOCK('somelock', 10)");
// Try to get the lock, wait for 10 secs to get it. If we can't get it within the 5 secs we have the script fails as we intend.
// Code which must be ACID here
?>[/code]
I was relying on the above to keep a transaction ACID, but I didn't realize that

[quote]The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself.[/quote]
The script itself [b]doesn't include calls the script makes[/b]. To me this is incredibly counter intuitive.

[code]<?php
set_time_limit(1);
set_ini('max_execution_time', 1);
sleep(50);
print "Surely this print command will never get run?!";
?>[/code]
The print command will get run.. incredible.

After having spent the last 3 hours tracking down a weird bug which I thought could only have been caused by an ACID violation I'll now have to spend the next hour trying to manually undo the damage done.

Use:
[code]<?php
list($success) = mysql_table(mysql_query("SELECT GET_LOCK('somelock', 10)"));
if ($success == 1) {
// Code which must be ACID here
}
?>[/code]
or use "LOCK TABLES asdf write, foobar write"
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.