﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	blockedby	blocking
2252	Simulierte Cron Jobs für ständige DB-Abfragen	noRiddle	somebody	"Wie ich hier
[https://www.modified-shop.org/forum/index.php?topic=12813.msg390607#msg390607 MODUL: Produkterinnerung für modified eCommerce Shopsoftware Antwort #384]
unter ""Zusatzidee:"" mal versucht habe darzulegen fände ich folgende Idee interessant und bedenkenswert:

Man lege eine DB-Tabelle an
{{{
CREATE TABLE simulated_cron_records (
  application varchar(32) NOT NULL,
  last_executed date DEFAULT NULL,
  PRIMARY KEY (application)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
}}}

und trage das Ausführen von Skripten die eigtl. nur einmal am Tag ausgeführt zu werden brauchen in diese Tabelle ein.
Die jeweiligen Skripte schauen dann lediglich, ob sie am heutigen Tag bereits ausgeführt wurden und wenn ja werden sie nicht erneut ausgeführt.
Das wäre z.B. sehr sinnvoll für das momentan noch bei jedem Seitenbaufruf ausgeführte ''xtc_expire_specials()''.

Auch für weitere, auch zukünftige, Aufgaben oder Custom-Applikationen wäre eine solche Vorgehensweise sinnvoll. Z.B. für Skripte die nicht lieferbare Artikel automatisch auf wieder lieferbar setzen wenn sich der Bestand von 0 auf X erhöht hat.

Für alle Skripte die nicht auch eine Uhrzeit sondern lediglich Tage berücksichtigen müssen wäre eine solche Implementation Klasse und würde die Performance des Shops verbessern.

Beispiel-Skript:

{{{
<?php
/*********************************
* my_application_script.php
*
*
*
*********************************/

$last_exec = NULL;
$mas_act = false;

$mas_last_exec_qu_str = ""SELECT last_executed FROM simulated_cron_records WHERE application = 'my_application_script' AND last_executed IS NOT NULL"";
$mas_last_exec_qu = xtc_db_query($mas_last_exec_qu_str);
if(xtc_db_num_rows($mas_last_exec_qu) == 1) {
  $mas_last_exec_arr = xtc_db_fetch_array($mas_last_exec_qu);
  $last_exec = $mas_last_exec_arr['last_executed'];

  //do it only once a day
  if($last_exec < date('Y-m-d', time()))
    $mas_act = true;
}

if(is_null($last_exec) || (isset($mas_act) && $mas_act === true)) {
  //do what ever this script is supposed to do

  //update set database record
  xtc_db_query(""INSERT INTO simulated_cron_records (application, last_executed) VALUES('my_application_script', NOW()) ON DUPLICATE KEY UPDATE last_executed = VALUES(last_executed)"");
}
?>
}}}


Gruß,
noRiddle
"	Neues Feature	new	normal		Shop	2.0.7.0					
