function updateUrlAggregates($url_id, $measurement_id) { # updating latest values for the URL $query = sprintf("UPDATE urls SET pagetest_last_id = %d, last_update = now(), pagetest_refresh_request = 0 WHERE id = %d", mysql_real_escape_string($measurement_id), mysql_real_escape_string($url_id)); $result = mysql_query($query); if (!$result) { beaconError(mysql_error()); } }
function updateUrlAggregates($url_id, $measurement_id) { global $cleanOldYSlowBeaconDetails; # updating latest values for the URL $query = sprintf("UPDATE urls SET har_last_id = %d, last_update = now() WHERE id = %d", mysql_real_escape_string($measurement_id), mysql_real_escape_string($url_id)); $result = mysql_query($query); if (!$result) { beaconError(mysql_error()); } }
function updateUrlAggregates($url_id, $measurement_id) { global $cleanOldYSlowBeaconDetails; # updating latest values for the URL $query = sprintf("UPDATE urls SET yslow2_last_id = %d, last_update = now(), y_refresh_request = 0 WHERE id = %d", mysql_real_escape_string($measurement_id), mysql_real_escape_string($url_id)); $result = mysql_query($query); if (!$result) { beaconError(mysql_error()); } // Clean old details for this URL to conserve space if ($cleanOldYSlowBeaconDetails) { # adding new entry $query = sprintf("/* clean old beacon details */\n\t\t\tUPDATE yslow2\n\t\t\tSET details = NULL\n\t\t\tWHERE url_id = '%d' AND id <> '%d'\n\t\t", mysql_real_escape_string($url_id), mysql_real_escape_string($measurement_id)); if (!mysql_query($query)) { beaconError(mysql_error()); } } }
function getUrlId($url, $outputerror = true) { global $dropQueryStrings; $url = validateURL($url, $outputerror); if (is_null($url)) { return null; } if ($dropQueryStrings) { $drop = false; if (is_array($dropQueryStrings)) { foreach ($dropQueryStrings as $prefix) { if (substr($url, 0, strlen($prefix)) == $prefix) { $drop = true; break; } } } else { $drop = true; } if ($drop) { $querypos = strpos($url, '?'); if ($querypos !== false) { $url = substr($url, 0, $querypos); } } } # get URL id $query = sprintf("SELECT id FROM urls WHERE url = '%s'", mysql_real_escape_string($url)); $result = mysql_query($query); if (!$result) { beaconError(mysql_error()); } if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); return $row['id']; } else { if (mysql_num_rows($result) == 0) { // Emulating unique index on a blob with unlimited length by locking the table on write // locking only when we're about to insert so we don't block the whole thing on every read // locking the table to make sure we pass it only by one concurrent process $result = mysql_query('LOCK TABLES urls WRITE'); if (!$result) { beaconError(mysql_error()); } // selecting the URL again to make sure there was no concurrent insert for this URL $query = sprintf("SELECT id FROM urls WHERE url = '%s'", mysql_real_escape_string($url)); $result = mysql_query($query); if (!$result) { $mysql_err = mysql_error(); mysql_query('UNLOCK TABLES'); // unlocking the table if in trouble beaconError($mysql_err); } // repeating the check if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); $url_id = $row['id']; } else { if (mysql_num_rows($result) == 0) { $query = sprintf("INSERT INTO urls (url) VALUES ('%s')", mysql_real_escape_string($url)); $result = mysql_query($query); if (!$result) { $mysql_err = mysql_error(); mysql_query('UNLOCK TABLES'); // unlocking the table if in trouble beaconError($mysql_err); } $url_id = mysql_insert_id(); } else { if (mysql_num_rows($result) > 1) { mysql_query('UNLOCK TABLES'); // unlocking the table if in trouble beaconError('more then one entry found for the URL (when lock is aquired)'); } } } $result = mysql_query('UNLOCK TABLES'); // now concurrent thread can try reading again if (!$result) { beaconError(mysql_error()); } return $url_id; } else { beaconError('more then one entry found for the URL'); } } }
$type = array_key_exists('type', $_GET) && $_GET['type'] != '' ? $_GET['type'] : FALSE; $start = array_key_exists('start', $_GET) && $_GET['start'] != '' ? $_GET['start'] : FALSE; $end = array_key_exists('end', $_GET) && $_GET['type'] != '' ? $_GET['end'] : FALSE; $resource_url = filter_var($_GET['resource_url'], FILTER_VALIDATE_URL); $query = sprintf('INSERT INTO event ( url_prefix, title, start' . ($type !== FALSE ? ', type' : '') . ($end !== FALSE ? ', end' : '') . ($resource_url !== FALSE ? ', resource_url' : '') . ") VALUES (\n\t\t\t'%s',\n\t\t\t'%s',\n\t\t\t'%s'" . ($type !== FALSE ? ", '%s'" : '') . ($end !== FALSE ? ", '%s'" : '') . ($resource_url !== FALSE ? ", '%s'" : '') . ')', mysql_real_escape_string($url), mysql_real_escape_string($_GET['title']), mysql_real_escape_string($start), mysql_real_escape_string($type), mysql_real_escape_string($end), mysql_real_escape_string($resource_url)); if (!mysql_query($query)) { beaconError(mysql_error()); } # updating last_event_update for the matching URLs $query = sprintf("UPDATE urls SET last_event_update = NOW() WHERE INSTR(url, '%s') = 1", mysql_real_escape_string($url)); $result = mysql_query($query); if (!$result) { beaconError(mysql_error()); } if (array_key_exists('manual', $_GET)) { ?> <html> <head> <title>Event added</title> </head> <body> <h1>Event added</h1> <p>Event successfully added.</p> <p>Add <a href="./">one more</a>.</p> </body></html> <?php exit; }
function getUrlId($url, $outputerror = true) { global $dropQueryStrings; $url = validateURL($url, $outputerror); if (is_null($url)) { return null; } if ($dropQueryStrings) { $drop = false; if (is_array($dropQueryStrings)) { foreach ($dropQueryStrings as $prefix) { if (substr($url, 0, strlen($prefix)) == $prefix) { $drop = true; break; } } } else { $drop = true; } if ($drop) { $querypos = strpos($url, '?'); if ($querypos !== false) { $url = substr($url, 0, $querypos); } } } $query = sprintf("INSERT IGNORE INTO urls (url, url_md5) VALUES ('%s', UNHEX(MD5('%s')))", mysql_real_escape_string($url), mysql_real_escape_string($url)); $result = mysql_query($query); # get URL id $query = sprintf("SELECT id FROM urls WHERE url_md5 = UNHEX(MD5('%s'))", mysql_real_escape_string($url)); $result = mysql_query($query); if (!$result) { beaconError(mysql_error()); } if (mysql_num_rows($result) > 1) { beaconError('More then one entry found for the URL even though MD5 is the same'); } else { if (mysql_num_rows($result) == 0) { beaconError('No entries found for the URL even though we just inserted it'); } } $row = mysql_fetch_assoc($result); return $row['id']; }