cvs: php4 /pear/Experimental/PEAR WebInstaller.php

From: Date: Sun, 08 Jul 2001 10:21:06 +0000
Subject: cvs: php4 /pear/Experimental/PEAR WebInstaller.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-232@lists.php.net to get a copy of this message
chregu Sun Jul 8 06:21:06 2001 EDT Modified files: /php4/pear/Experimental/PEAR WebInstaller.php Log: reads Packages.xml.gz if it's available on the serverside (and zlib is compiled) caches the Packages-File Index: php4/pear/Experimental/PEAR/WebInstaller.php diff -u php4/pear/Experimental/PEAR/WebInstaller.php:1.2 php4/pear/Experimental/PEAR/WebInstaller.php:1.3 --- php4/pear/Experimental/PEAR/WebInstaller.php:1.2 Sat Jul 7 18:47:18 2001 +++ php4/pear/Experimental/PEAR/WebInstaller.php Sun Jul 8 06:21:06 2001 @@ -52,14 +52,15 @@ * take the writeable off the directory..) * * TODO: - * - Caching of Package.xml (it doesn't need to be downloaded everytime) * - Grouping of Packages * - Show installed Packages (from /var/lib/php/packages.lst?) * - Add possibility to install a package (.tgz) from the local file * system without a global Packages.xml (useful if no cgi-php * around and you need this package you downloaded installed :) ) * - Search Function (maybe needed if we have hundreds of packages) + * - Only download Packages.xml, if it actually changed. * + * This Code is highly experimental. */ require_once "PEAR.php"; @@ -93,6 +94,9 @@ */ var $installdir; + /** how many seconds we should cache Packages.xml */ + var $cachetime = 3600; + // }}} // {{{ constructor @@ -216,7 +220,7 @@ function printTable() { - $Packages = $this->infoFromDescriptionFile($this->remotedir."Packages.xml"); + $Packages = $this->getPackages(); if (PEAR::IsError($Packages)) { print $Packages->message; @@ -304,6 +308,50 @@ } // }}} + + function getPackages () + { + + // if we can write to the installdir cache the Packages.xml there + if ( is_writeable($this->installdir."/Packages.xml") || !file_exists($this->installdir."/Packages.xml") && is_writeable($this->installdir) ) + { + $time = filemtime($this->installdir."/Packages.xml"); + + if ($time < (time () - $this->cachetime )) { + print "Package-File to old. Get new one.<br>"; + if (function_exists("gzfile") && $fp = @fopen($this->remotedir."/Packages.xml.gz","r")) { + $fout = fopen($this->installdir."/Packages.xml.gz","w"); + while ($data = fread($fp,8192)) { + fwrite ($fout, $data); + } + fclose($fout); + } + else + { + $data = file ($this->remotedir."/Packages.xml", "r"); + $fout = fopen($this->installdir."/Packages.xml","w"); + fwrite ($fout, $data); + fclose($fout); + } + + } + if (file_exists($this->installdir."/Packages.xml.gz")) + { + $Packages = $this->infoFromDescriptionFile($this->installdir."/Packages.xml.gz",True); + } + else + { + $Packages = $this->infoFromDescriptionFile($this->installdir."/Packages.xml"); + } + } + + else + { + $Packages = $this->infoFromDescriptionFile($this->remotedir."/Packages.xml"); + } + return $Packages; + } + function printCell($text) { if ($text) @@ -388,9 +436,9 @@ // }}} // {{{ infoFromDescriptionFile() - function infoFromDescriptionFile($descfile) + function infoFromDescriptionFile($descfile,$GzFormat) { - $fp = @fopen($descfile, "r"); + $fp = @file_exists($descfile); if (!$fp) { return $this->raiseError("Unable to open $descfile"); } @@ -413,7 +461,14 @@ // read the whole thing so we only get one cdata callback // for each block of cdata - $data = fread($fp,8912); + if ($GzFormat && function_exists("gzfile") ) + { + $data = implode("",gzfile($descfile)); + } + else + { + $data = implode("",file($descfile)); + } if (!@xml_parse($xp, $data, 1)) { $msg = sprintf("XML error: %s at line %d",

« previous php.pear.cvs (#232) next »