From 168ae40dd25ee827e9bcb01e27e52c0e203c21d6 Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Thu, 14 Jun 2012 20:58:25 -0600 Subject: add rudimentary locking capability to Friendica functions --- include/lock.php | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 include/lock.php (limited to 'include/lock.php') diff --git a/include/lock.php b/include/lock.php new file mode 100644 index 000000000..be6130e1d --- /dev/null +++ b/include/lock.php @@ -0,0 +1,76 @@ + Date: Thu, 14 Jun 2012 21:01:59 -0600 Subject: cleanup obsolete comments --- include/lock.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'include/lock.php') diff --git a/include/lock.php b/include/lock.php index be6130e1d..6d7bf6055 100644 --- a/include/lock.php +++ b/include/lock.php @@ -2,8 +2,6 @@ // Provide some ability to lock a PHP function so that multiple processes // can't run the function concurrently -// The function must have a line inserted into the 'lock' table with the -// function's name in the 'name' field if(! function_exists('lock_function')) { function lock_function($fn_name, $block = true, $wait_sec = 2) { if( $wait_sec == 0 ) -- cgit v1.2.3 From 46068935d0c45a63cf34979859063a23314d18b7 Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Sat, 16 Jun 2012 11:28:44 -0600 Subject: minor cleanup in lock.php --- include/lock.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/lock.php') diff --git a/include/lock.php b/include/lock.php index 6d7bf6055..cc2888c0a 100644 --- a/include/lock.php +++ b/include/lock.php @@ -72,3 +72,5 @@ function unlock_function(fn_name) { return; }} + +?> -- cgit v1.2.3 From 75ed37fb3d17d97d73a53a62c10caa3a4d11c632 Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Sun, 17 Jun 2012 11:25:36 -0600 Subject: "lock" is a reserved MySQL keyword --- include/lock.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'include/lock.php') diff --git a/include/lock.php b/include/lock.php index cc2888c0a..e7e176eee 100644 --- a/include/lock.php +++ b/include/lock.php @@ -10,19 +10,19 @@ function lock_function($fn_name, $block = true, $wait_sec = 2) { $got_lock = false; do { - q("LOCK TABLE lock WRITE"); - $r = q("SELECT locked FROM lock WHERE name = '%s' LIMIT 1", + q("LOCK TABLE locks WRITE"); + $r = q("SELECT locked FROM locks WHERE name = '%s' LIMIT 1", dbesc($fn_name) ); if((count($r)) && (! $r[0]['locked'])) { - q("UPDATE lock SET locked = 1 WHERE name = '%s' LIMIT 1", + q("UPDATE locks SET locked = 1 WHERE name = '%s' LIMIT 1", dbesc($fn_name) ); $got_lock = true; } elseif(! $r) { // the Boolean value for count($r) should be equivalent to the Boolean value of $r - q("INSERT INTO lock ( name, locked ) VALUES ( '%s', 1 )", + q("INSERT INTO locks ( name, locked ) VALUES ( '%s', 1 )", dbesc($fn_name) ); $got_lock = true; @@ -47,7 +47,7 @@ function block_on_function_lock($fn_name, $wait_sec = 2) { $wait_sec = 2; // don't let the user pick a value that's likely to crash the system do { - $r = q("SELECT locked FROM lock WHERE name = '%s' LIMIT 1", + $r = q("SELECT locked FROM locks WHERE name = '%s' LIMIT 1", dbesc(fn_name) ); @@ -63,7 +63,7 @@ function block_on_function_lock($fn_name, $wait_sec = 2) { if(! function_exists('unlock_function')) { function unlock_function(fn_name) { //$r = q("LOCK TABLE lock WRITE"); - $r = q("UPDATE lock SET locked = 0 WHERE name = '%s' LIMIT 1", + $r = q("UPDATE locks SET locked = 0 WHERE name = '%s' LIMIT 1", dbesc(fn_name) ); //$r = q("UNLOCK TABLES"); -- cgit v1.2.3 From e0607e0238b52ed47c2330792694f4a72af0dba4 Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Sat, 23 Jun 2012 14:25:18 -0600 Subject: cleanup some syntax errors in lock.php --- include/lock.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'include/lock.php') diff --git a/include/lock.php b/include/lock.php index e7e176eee..9bdb71125 100644 --- a/include/lock.php +++ b/include/lock.php @@ -48,7 +48,7 @@ function block_on_function_lock($fn_name, $wait_sec = 2) { do { $r = q("SELECT locked FROM locks WHERE name = '%s' LIMIT 1", - dbesc(fn_name) + dbesc($fn_name) ); if(count($r) && $r[0]['locked']) @@ -61,14 +61,14 @@ function block_on_function_lock($fn_name, $wait_sec = 2) { if(! function_exists('unlock_function')) { -function unlock_function(fn_name) { +function unlock_function($fn_name) { //$r = q("LOCK TABLE lock WRITE"); $r = q("UPDATE locks SET locked = 0 WHERE name = '%s' LIMIT 1", - dbesc(fn_name) + dbesc($fn_name) ); //$r = q("UNLOCK TABLES"); - logger('unlock_function: released lock for function ' . fn_name, LOGGER_DEBUG); + logger('unlock_function: released lock for function ' . $fn_name, LOGGER_DEBUG); return; }} -- cgit v1.2.3