$method) { if (isset($contacts[$id][$name])) { echo("Contact makes use of $name, gathering information\n"); if (!isset($cache[$name])) $cache[$name] = []; if (!isset($cache[$name][$contacts[$id][$name]])) $cache[$name][$contacts[$id][$name]] = [ "data" => null, "update" => 0 ]; if (time() - $cache[$name][$contacts[$id][$name]]["update"] > 86400 || isset($cache[$name][$contacts[$id][$name]]["data"]["error"])) { echo(" Information is out of date, updating it\n"); $return = []; $cmd = "cd \"$_SERVER[DOCUMENT_ROOT]/includes/external/addressbook\" && node \"$_SERVER[DOCUMENT_ROOT]/includes/external/addressbook/$name.js\" \"" . str_replace('"', "''", $contacts[$id][$name]) . "\""; exec("nice -n 19 " . $cmd, $return); $json = trim(implode("\n", $return)); $cache[$name][$contacts[$id][$name]] = [ "data" => json_decode($json), "update" => time() ]; echo(" Information updated\n"); } else { echo(" Information is up to date, not updating it\n"); } } else { echo("Contact does not makes use of $name\n"); } } echo("Done!\n"); file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/addressbook/saved.json", json_encode($cache));