1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-13 20:45:55 +00:00

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

This commit is contained in:
Andrew Dolgov
2013-09-02 12:33:59 +04:00
parent f73e03e000
commit a33558a61e
3 changed files with 28 additions and 1 deletions

View File

@@ -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);
}
}