diff --git a/includes/dbFacile.mysql.php b/includes/dbFacile.mysql.php index 0d1d7150c..44dc5d494 100644 --- a/includes/dbFacile.mysql.php +++ b/includes/dbFacile.mysql.php @@ -59,6 +59,34 @@ function dbQuery($sql, $parameters=array()) { }//end dbQuery() +/* + * Aquire a lock on a string + * */ +function dbGetLock($data, $timeout = 0) { + $sql = 'SELECT GET_LOCK(\'' . $data . '\',' . $timeout . ')'; + echo "printing sql: "; + echo "$sql\n"; + $result = dbFetchCell($sql); + echo "printing result: "; + echo "$result\n"; + return $result; +} + + +/* + * Release a lock on a string + * */ +function dbReleaseLock($data, $timeout = 0) { + $sql = 'SELECT RELEASE_LOCK(\'' . $data . '\')'; + echo "printing sql: "; + echo "$sql\n"; + $result = dbFetchCell($sql); + echo "printing result: "; + echo "$result\n"; + return $result; +} + + /* * Passed an array and a table name, it attempts to insert the data into the table. * Check for boolean false to determine whether insert failed diff --git a/includes/dbFacile.mysqli.php b/includes/dbFacile.mysqli.php index 2408ca990..7b48ad6b9 100644 --- a/includes/dbFacile.mysqli.php +++ b/includes/dbFacile.mysqli.php @@ -59,6 +59,33 @@ function dbQuery($sql, $parameters=array()) { }//end dbQuery() +/* + * Aquire a lock on a string + * */ +function dbGetLock($data, $timeout = 0) { + $sql = 'SELECT GET_LOCK(\'' . $data . '\',' . $timeout . ')'; + echo "printing sql: "; + echo "$sql\n"; + $result = dbFetchCell($sql); + echo "printing result: "; + echo "$result\n"; + return $result; +} + + +/* + * Release a lock on a string + * */ +function dbReleaseLock($data, $timeout = 0) { + $sql = 'SELECT RELEASE_LOCK(\'' . $data . '\')'; + echo "printing sql: "; + echo "$sql\n"; + $result = dbFetchCell($sql); + echo "printing result: "; + echo "$result\n"; + return $result; +} + /* * Passed an array and a table name, it attempts to insert the data into the table. * Check for boolean false to determine whether insert failed diff --git a/poller.php b/poller.php index 6412c37be..8c2b32881 100755 --- a/poller.php +++ b/poller.php @@ -110,9 +110,11 @@ if (!isset($query)) { foreach (dbFetch($query) as $device) { $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = '".$device['device_id']."'"); - poll_device($device, $options); - RunRules($device['device_id']); - echo "\r\n"; + if (dbGetLock('polling.' . $device['device_id'])) { + poll_device($device, $options); + RunRules($device['device_id']); + echo "\r\n"; + } $polled_devices++; }