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
https://forums.phpfreaks.com/topic/27662-warning-get_lock-and-set_time_limit/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.