Browse Source

add log settings for scrape and sitemap crontab tasks

main
ghost 1 year ago
parent
commit
3e70bc9c2a
  1. 6
      example/environment/env.example.php
  2. 49
      src/crontab/scrape.php
  3. 49
      src/crontab/sitemap.php

6
example/environment/env.example.php

@ -179,6 +179,12 @@ define('API_IMPORT_MAGNET_VIEWS_ENABLED', true); // depends of API_IMP @@ -179,6 +179,12 @@ define('API_IMPORT_MAGNET_VIEWS_ENABLED', true); // depends of API_IMP
// Logs
define('LOG_DIRECTORY', __DIR__ . '/../storage/log');
define('LOG_CRONTAB_SCRAPE_ENABLED', true);
define('LOG_CRONTAB_SCRAPE_FILENAME', sprintf('crontab_scrape_%s.log', date('Y-m-d')));
define('LOG_CRONTAB_SITEMAP_ENABLED', true);
define('LOG_CRONTAB_SITEMAP_FILENAME', sprintf('crontab_sitemap_%s.log', date('Y-m-d')));
define('LOG_CRONTAB_EXPORT_FEED_ENABLED', true);
define('LOG_CRONTAB_EXPORT_FEED_FILENAME', sprintf('crontab_export_feed_%s.log', date('Y-m-d')));

49
src/crontab/scrape.php

@ -17,6 +17,16 @@ $debug = [ @@ -17,6 +17,16 @@ $debug = [
'ISO8601' => date('c'),
'total' => microtime(true),
],
'http' =>
[
'total' => 0,
],
'memory' =>
[
'start' => memory_get_usage(),
'total' => 0,
'peaks' => 0
],
];
// Init Scraper
@ -121,17 +131,28 @@ try { @@ -121,17 +131,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,
]
]
])
);
$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_SCRAPE_ENABLED)
{
@mkdir(LOG_DIRECTORY, 0774, true);
if ($handle = fopen(LOG_DIRECTORY . '/' . LOG_CRONTAB_SCRAPE_FILENAME, 'a+'))
{
fwrite($handle, print_r($debug, true));
fclose($handle);
chmod(LOG_DIRECTORY . '/' . LOG_CRONTAB_SCRAPE_FILENAME, 0774);
}
}

49
src/crontab/sitemap.php

@ -17,6 +17,16 @@ $debug = [ @@ -17,6 +17,16 @@ $debug = [
'ISO8601' => date('c'),
'total' => microtime(true),
],
'http' =>
[
'total' => 0,
],
'memory' =>
[
'start' => memory_get_usage(),
'total' => 0,
'peaks' => 0
],
];
// Begin
@ -49,17 +59,28 @@ try { @@ -49,17 +59,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,
]
]
])
);
$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_SITEMAP_ENABLED)
{
@mkdir(LOG_DIRECTORY, 0774, true);
if ($handle = fopen(LOG_DIRECTORY . '/' . LOG_CRONTAB_SITEMAP_FILENAME, 'a+'))
{
fwrite($handle, print_r($debug, true));
fclose($handle);
chmod(LOG_DIRECTORY . '/' . LOG_CRONTAB_SITEMAP_FILENAME, 0774);
}
}
Loading…
Cancel
Save