summaryrefslogtreecommitdiff
path: root/include/functions.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-09-02 12:33:59 +0400
committerAndrew Dolgov <[email protected]>2013-09-02 12:33:59 +0400
commita33558a61efc244ad8c809748e6ee64413e3a217 (patch)
treea84d96dc58ca3cb7981443389b9ce7f6b7b42c19 /include/functions.php
parentf73e03e000d7119b8c9724790e70e4da4fb32cfe (diff)
pass logfile to child tasks if locking is possible, lock logfile before writing, add kludge to prevent update_rss_feed unneeded debugging go into master logfile
Diffstat (limited to 'include/functions.php')
-rw-r--r--include/functions.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/include/functions.php b/include/functions.php
index 2d6716b81..8ede14a0b 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -139,6 +139,8 @@
* @return void
*/
function _debug($msg, $show = true) {
+ if (defined('SUPPRESS_DEBUGGING'))
+ return false;
$ts = strftime("%H:%M:%S", time());
if (function_exists('posix_getpid')) {
@@ -153,7 +155,29 @@
$fp = fopen(LOGFILE, 'a+');
if ($fp) {
+ $locked = false;
+
+ if (function_exists("flock")) {
+ $tries = 0;
+
+ // try to lock logfile for writing
+ while ($tries < 5 && !$locked = flock($fp, LOCK_EX | LOCK_NB)) {
+ sleep(1);
+ ++$tries;
+ }
+
+ if (!$locked) {
+ fclose($fp);
+ return;
+ }
+ }
+
fputs($fp, "[$ts] $msg\n");
+
+ if (function_exists("flock")) {
+ flock($fp, LOCK_UN);
+ }
+
fclose($fp);
}
}