svn: /web/php-master/trunk/scripts/ mirror-test
| From: | Daniel P. Brown | Date: | Mon, 16 May 2011 16:01:24 +0000 |
| Subject: | svn: /web/php-master/trunk/scripts/ mirror-test | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-11016@lists.php.net to get a copy of this message | ||
danbrown Mon, 16 May 2011 16:01:24 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=311097
Log:
Too hasty with the ENTER key....
Changed paths:
U web/php-master/trunk/scripts/mirror-test
Modified: web/php-master/trunk/scripts/mirror-test
===================================================================
--- web/php-master/trunk/scripts/mirror-test 2011-05-16 15:52:31 UTC (rev 311096)
+++ web/php-master/trunk/scripts/mirror-test 2011-05-16 16:01:24 UTC (rev 311097)
@@ -1,4 +1,4 @@
-#!/usr/bin/php -q
+#!/local/php5/bin/php -q
<?php # vim: ft=php et
// This script is executed on master
@@ -19,46 +19,25 @@
set_time_limit(30 * 60);
// Connect to local MySQL database
-mysql_connect("localhost", "root", "") or die("unable to connect
to database");
+mysql_connect("localhost", "nobody", "") or die("unable to
connect to database");
mysql_select_db("phpmasterdb");
-// Allow for single-mirror testing so that we can manually test mirrors.
-if (!isset($argv[1])) {
+// Get mirror information for all active mirrors (regardless of their type!)
+$query = "SELECT maintainer, hostname, id, has_search, has_stats, lang,
+ UNIX_TIMESTAMP(lastchecked) as lastchecked,
+ UNIX_TIMESTAMP(lastupdated) AS lastupdated
+ FROM mirrors WHERE active = 1";
+$result = mysql_query($query) or die("unable to get from the database: " .
mysql_error());
- // Get mirror information for all active mirrors (regardless of their type!)
- $query = "SELECT maintainer, hostname, id, has_search, has_stats, lang,
- UNIX_TIMESTAMP(lastchecked) as lastchecked,
- UNIX_TIMESTAMP(lastupdated) AS lastupdated
- FROM mirrors WHERE active = 1";
- $result = mysql_query($query) or die("unable to get from the database: " .
mysql_error());
-
- // Get all mirror site data to the $hosts array
- $hosts = array();
- while ($row = mysql_fetch_array($result)) {
- $hosts[] = $row;
- }
-
- // Free up the result to get more memory
- mysql_free_result($result);
-
-} else {
-
- // Get the data for just a single mirror, by request.
- $query = "SELECT maintainer, hostname, id, has_search, has_stats, lang,
- UNIX_TIMESTAMP(lastchecked) as lastchecked,
- UNIX_TIMESTAMP(lastupdated) AS lastupdated
- FROM mirrors WHERE
hostname='".mysql_real_escape_string($argv[1])."' LIMIT 0,1";
-
- $result = mysql_query($query) or die("Unable to access mirror record. Perhaps
'".$argv[1]."' does not exist. Error: ".mysql_error().PHP_EOL."SQL
Query: ".$query.PHP_EOL);
-
- // Get the data and populate the $hosts array, which will interface with the rest of the legacy
code.
- $hosts[] = mysql_fetch_array($result);
-
- // And, again like above, free up the memory by killing the MySQL connection.
- mysql_free_result($result);
-
+// Get all mirror site data to the $hosts array
+$hosts = array();
+while ($row = mysql_fetch_array($result)) {
+ $hosts[] = $row;
}
+// Free up the result to get more memory
+mysql_free_result($result);
+
// Check host for errors, inject data into $data and $problem
function host_has_error($hostname, $filename, &$data, &$problem) {
@@ -126,8 +105,6 @@
// Get all mirror sites, and count the index of them
foreach ($hosts as $index => $host) {
- echo 'Testing '.$host['hostname'].'.'.PHP_EOL;
-
// Request the exact file on www.php.net as it redirects
// shortcut requests to a mirror site, and we would not handle
// that properly. Otherwise on a mirror site we need to check
@@ -168,7 +145,7 @@
$hosts[$index]['disable'] = true;
$hosts[$index]['problem'] = "Invalid last update time.";
}
-
+
// If new search information is available, override previous one
/*if (in_array($info[3], array('0', '1', '2'))) {
$hosts[$index]['has_search'] = $info[3];
@@ -331,8 +308,8 @@
"lang = '" . $host['lang'] .
"', " .
"ocmt = '' " .
"WHERE hostname = '" . $host['hostname'] .
"'";
-
- $result = mysql_query($query) or die("Unable to update the database: $query: " .
mysql_error().PHP_EOL);
+
+ $result = mysql_query($query) or die("unable to update the database: $query: " .
mysql_error());
if ($result) { $mirrorsupdated++; }
else { $problems .= $host['hostname'] . "\t- cannot be updated in
database\n"; }
}
@@ -350,7 +327,7 @@
"lastupdated = FROM_UNIXTIME(" . $host['lastupdated'] .
") " .
"WHERE hostname = '" . $host['hostname'] .
"'";
}
- $result = mysql_query($query) or die("Unable to update the database: $query: " .
mysql_error());
+ $result = mysql_query($query) or die("unable to update the database: $query: " .
mysql_error());
$problems .= $host['hostname'] . "\t- " . $host['problem'] .
"\n";
}
@@ -359,7 +336,7 @@
// Send a debug mail at midnight with current details
if (intval(date("H")) == 0) {
@mail(
- "bjori@php.net,danbrown@php.net",
+ "bjori@php.net",
"Mirror site updates done",
"$mirrorsupdated mirror sites properly updated (out of " . count($hosts) .
")\n\nProblematic mirrors:\n\n" . $problems
);
@@ -367,8 +344,9 @@
// If less then 70 mirrors updated there is something severly wrong. mail it.
if ($mirrorsupdated < 70) {
@mail(
- "php-webmaster@lists.php.net,danbrown@php.net",
+ "php-webmaster@lists.php.net",
"[CRITICAL] Mirror site updates failure",
"$mirrorsupdated mirror sites properly updated (out of " . count($hosts) .
")\n\nProblematic mirrors:\n\n" . $problems
);
}
+