cvs: php-master-web /scripts mirror-test

From: Date: Sun, 08 Sep 2002 21:34:40 +0000
Subject: cvs: php-master-web /scripts mirror-test
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-12359@lists.php.net to get a copy of this message
jimw Sun Sep 8 17:34:40 2002 EDT Modified files: /php-master-web/scripts mirror-test Log: convert to pure php. it doesn't need to run super-fast. Index: php-master-web/scripts/mirror-test diff -u php-master-web/scripts/mirror-test:1.11 php-master-web/scripts/mirror-test:1.12 --- php-master-web/scripts/mirror-test:1.11 Wed Aug 14 15:41:37 2002 +++ php-master-web/scripts/mirror-test Sun Sep 8 17:34:39 2002 @@ -1,5 +1,5 @@ #!/usr/local/bin/php -q -<?php +<?php # vim: ft=php set_time_limit (0); /* simple testing system to ping each mirror, and see what state they are in.*/ @@ -14,65 +14,38 @@ $result = mysql_query($query) or die("unable to get from the database: ".mysql_error()); +$total = mysql_num_rows($result); + for($i=0; $row = mysql_fetch_array($result,MYSQL_ASSOC); $i++) { $hosts[$i]['hostname'] = $row['hostname']; $hosts[$i]['id'] = $row['id']; $hosts[$i]['maintainer'] = $row['maintainer']; -} - -/* now this stage takes a long time, and we need to go out of PHP to execute it, - so we are going to write that info to a file */ - -$rv = ""; -$total = sizeof($hosts); - -for($i=0; $i < $total; $i++) { - - $rv .= $hosts[$i]['hostname'] . " "; -} - -$d = date("U"); -$mf = <<< EOF -CCS = $rv -DAT = $d -TMP = /tmp/mirrors/data/ -DIR = /tmp/mirrors/ -LOG = /tmp/mirrors/log -SAV = /tmp/mold/ - -all: \${CCS} - -\${CCS}: start -\t/home/imajes/bin/wget --verbose --debug --tries=1 --timeout=15 -a $(LOG) http://$@/mirror-info.php -O $(TMP)$@ -start: -\tmkdir -p $(TMP) - -clean: -\ttar zcf $(SAV)$(DAT).tar.gz $(DIR) -\trm -rf $(DIR) -#\tkillall wget #isn't currently needed, but some versions of wget suck (use latest cvs). - -EOF; - -/* now put this into a makefile, so we can batch process it */ - -@mkdir("/tmp/mirrors", 0777); - -$fp = @fopen("/tmp/mirrors/Makefile", "w"); -$fw = @fwrite($fp, $mf); -@fclose($fp); - -/* execute it, gather data... */ - -exec("make -C /tmp/mirrors/ -i -j -k all 2> /dev/null"); - -/* now get the info from the files and populate our arrays of data */ - -for ($i=0; $i < $total; $i++) { - $file = "/tmp/mirrors/data/" . $hosts[$i]['hostname']; - $fp = @fopen($file, "r"); - $rv = @fread($fp, 1000); + $fp = fsockopen($row['hostname'], 80, $errno, $errstr, 15); + if (!$fp) { + echo "unable to connect to $row[hostname]\n"; + continue; + } + + $rc = fputs($fp, "GET /mirror-info.php HTTP/1.0\r\nHost: $row[hostname]\r\n\r\n"); + if ($rc < 0) continue; + socket_set_timeout($fp, 5, 0); + + do { + $line = fgets($fp); + } while ($line !== false && $line != "\r\n" && $line != "\n"); + + if ($line === false) { + echo "didn't get past headers for $row[hostname]\n"; + continue; + } + + $rv = fgets($fp); + + if ($rv === false) { + echo "didn't get data for $row[hostname]\n"; + continue; + } $info = explode("|", $rv); $hosts[$i]['phpversion'] = $info[1]; @@ -80,18 +53,9 @@ $hosts[$i]['xtra'] = $info[3]; } -/* reconnect to the database */ -mysql_connect("localhost","nobody","") or die("unable to connect to database"); -mysql_select_db("php3"); - for($i=0; $i < $total; $i++) { if ($hosts[$i]['lastupdate']) { $query = "UPDATE mirrors SET lastchecked=NOW(),lastupdated=FROM_UNIXTIME(".$hosts[$i]['lastupdate']."),phpversion='".addslashes($hosts[$i]['phpversion'])."' WHERE hostname = '" . $hosts[$i]['hostname'] . "'"; $result = mysql_query($query) or die("unable to update the database: $query: ".mysql_error()); } } - -/* this cleans what we did. it also kills all the wget sessions that didn't end - however, the make session -goes defunct and loses reporting over the child processes. This should die within a short period of time. */ - -exec("make -C /tmp/mirrors/ -k -i clean 2> /dev/null");

« previous php.mirrors (#12359) next »