diff --git a/.gitignore b/.gitignore index 0cd77c8..21c589b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,13 +6,15 @@ /src/public/api/*.json -/src/config/* +/src/config/ !/src/config/bootstrap.php !/src/config/nodes.php !/src/config/trackers.php /src/public/sitemap.xml +/src/storage/log/*.log + /composer.lock *test* \ No newline at end of file diff --git a/example/environment/env.example.php b/example/environment/env.example.php index 1f430ec..efd0c45 100644 --- a/example/environment/env.example.php +++ b/example/environment/env.example.php @@ -174,4 +174,19 @@ define('API_IMPORT_MAGNET_DOWNLOADS_ENABLED', true); // depends of API_IMP define('API_IMPORT_MAGNET_COMMENTS_ENABLED', true); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED, API_IMPORT_MAGNETS_ENABLED define('API_IMPORT_MAGNET_COMMENTS_APPROVED_ONLY', false); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED, API_IMPORT_MAGNETS_ENABLED, API_IMPORT_MAGNET_COMMENTS_ENABLED define('API_IMPORT_MAGNET_STARS_ENABLED', true); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED, API_IMPORT_MAGNETS_ENABLED -define('API_IMPORT_MAGNET_VIEWS_ENABLED', true); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED, API_IMPORT_MAGNETS_ENABLED \ No newline at end of file +define('API_IMPORT_MAGNET_VIEWS_ENABLED', true); // depends of API_IMPORT_ENABLED, API_IMPORT_USERS_ENABLED, API_IMPORT_MAGNETS_ENABLED + +// Logs +define('LOG_DIRECTORY', __DIR__ . '/../storage/log'); + +define('LOG_CRONTAB_EXPORT_FEED_ENABLED', true); +define('LOG_CRONTAB_EXPORT_FEED_FILENAME', sprintf('crontab_export_feed_%s.log', date('Y-m-d'))); + +define('LOG_CRONTAB_EXPORT_PUSH_ENABLED', true); +define('LOG_CRONTAB_EXPORT_PUSH_FILENAME', sprintf('crontab_export_push_%s.log', date('Y-m-d'))); + +define('LOG_CRONTAB_IMPORT_FEED_ENABLED', true); +define('LOG_CRONTAB_IMPORT_FEED_FILENAME', sprintf('crontab_import_feed_%s.log', date('Y-m-d'))); + +define('LOG_API_PUSH_ENABLED', true); +define('LOG_API_PUSH_FILENAME', sprintf('api_push_%s.log', date('Y-m-d'))); \ No newline at end of file diff --git a/src/crontab/export/feed.php b/src/crontab/export/feed.php index 2d335e7..6d28745 100644 --- a/src/crontab/export/feed.php +++ b/src/crontab/export/feed.php @@ -5,7 +5,7 @@ $semaphore = sem_get(crc32('yggtracker.crontab.export.feed'), 1); if (false === sem_acquire($semaphore, true)) { - exit (PHP_EOL . 'yggtracker.crontab.export.feed process locked by another thread.' . PHP_EOL); + exit (_('yggtracker.crontab.export.feed process locked by another thread.')); } // Bootstrap @@ -14,10 +14,21 @@ require_once __DIR__ . '/../../config/bootstrap.php'; // Init Debug $debug = [ + 'dump' => [], 'time' => [ 'ISO8601' => date('c'), 'total' => microtime(true), ], + 'http' => + [ + 'total' => 0, + ], + 'memory' => + [ + 'start' => memory_get_usage(), + 'total' => 0, + 'peaks' => 0 + ], ]; // Define public registry @@ -519,17 +530,28 @@ try } // Debug output -$debug['time']['total'] = microtime(true) - $debug['time']['total']; - -print_r( - array_merge($debug, [ - 'db' => [ - 'total' => [ - 'select' => $db->getDebug()->query->select->total, - 'insert' => $db->getDebug()->query->insert->total, - 'update' => $db->getDebug()->query->update->total, - 'delete' => $db->getDebug()->query->delete->total, - ] - ] - ]) -); \ No newline at end of file +$debug['time']['total'] = microtime(true) - $debug['time']['total']; + +$debug['memory']['total'] = memory_get_usage() - $debug['memory']['start']; +$debug['memory']['peaks'] = memory_get_peak_usage(); + +$debug['db']['total']['select'] = $db->getDebug()->query->select->total; +$debug['db']['total']['insert'] = $db->getDebug()->query->insert->total; +$debug['db']['total']['update'] = $db->getDebug()->query->update->total; +$debug['db']['total']['delete'] = $db->getDebug()->query->delete->total; + +print_r($debug); + +// Debug log +if (LOG_CRONTAB_EXPORT_FEED_ENABLED) +{ + @mkdir(LOG_DIRECTORY, 0770, true); + + if ($handle = fopen(LOG_DIRECTORY . '/' . LOG_CRONTAB_EXPORT_FEED_FILENAME, 'a+')) + { + fwrite($handle, print_r($debug, true)); + fclose($handle); + + chmod(LOG_DIRECTORY . '/' . LOG_CRONTAB_EXPORT_FEED_FILENAME, 0770); + } +} \ No newline at end of file diff --git a/src/crontab/export/push.php b/src/crontab/export/push.php index 29e5971..29ca436 100644 --- a/src/crontab/export/push.php +++ b/src/crontab/export/push.php @@ -14,12 +14,21 @@ require_once __DIR__ . '/../../config/bootstrap.php'; // Init Debug $debug = [ - 'time' => - [ + 'dump' => [], + 'time' => [ 'ISO8601' => date('c'), 'total' => microtime(true), ], - 'result' => [] + 'http' => + [ + 'total' => 0, + ], + 'memory' => + [ + 'start' => memory_get_usage(), + 'total' => 0, + 'peaks' => 0 + ], ]; // Define public registry @@ -365,17 +374,28 @@ else } // Debug output -$debug['time']['total'] = microtime(true) - $debug['time']['total']; - -print_r( - array_merge($debug, [ - 'db' => [ - 'total' => [ - 'select' => $db->getDebug()->query->select->total, - 'insert' => $db->getDebug()->query->insert->total, - 'update' => $db->getDebug()->query->update->total, - 'delete' => $db->getDebug()->query->delete->total, - ] - ] - ]) -); \ No newline at end of file +$debug['time']['total'] = microtime(true) - $debug['time']['total']; + +$debug['memory']['total'] = memory_get_usage() - $debug['memory']['start']; +$debug['memory']['peaks'] = memory_get_peak_usage(); + +$debug['db']['total']['select'] = $db->getDebug()->query->select->total; +$debug['db']['total']['insert'] = $db->getDebug()->query->insert->total; +$debug['db']['total']['update'] = $db->getDebug()->query->update->total; +$debug['db']['total']['delete'] = $db->getDebug()->query->delete->total; + +print_r($debug); + +// Debug log +if (LOG_CRONTAB_EXPORT_PUSH_ENABLED) +{ + @mkdir(LOG_DIRECTORY, 0770, true); + + if ($handle = fopen(LOG_DIRECTORY . '/' . LOG_CRONTAB_EXPORT_PUSH_FILENAME, 'a+')) + { + fwrite($handle, print_r($debug, true)); + fclose($handle); + + chmod(LOG_DIRECTORY . '/' . LOG_CRONTAB_EXPORT_PUSH_FILENAME, 0770); + } +} \ No newline at end of file diff --git a/src/crontab/import/feed.php b/src/crontab/import/feed.php index 7c0d1b0..226e171 100644 --- a/src/crontab/import/feed.php +++ b/src/crontab/import/feed.php @@ -1141,4 +1141,18 @@ $debug['db']['total']['insert'] = $db->getDebug()->query->insert->total; $debug['db']['total']['update'] = $db->getDebug()->query->update->total; $debug['db']['total']['delete'] = $db->getDebug()->query->delete->total; -print_r($debug); \ No newline at end of file +print_r($debug); + +// Debug log +if (LOG_CRONTAB_IMPORT_FEED_ENABLED) +{ + @mkdir(LOG_DIRECTORY, 0770, true); + + if ($handle = fopen(LOG_DIRECTORY . '/' . LOG_CRONTAB_IMPORT_FEED_FILENAME, 'a+')) + { + fwrite($handle, print_r($debug, true)); + fclose($handle); + + chmod(LOG_DIRECTORY . '/' . LOG_CRONTAB_IMPORT_FEED_FILENAME, 0770); + } +} \ No newline at end of file diff --git a/src/storage/log/index.html b/src/storage/log/index.html new file mode 100644 index 0000000..e69de29