Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.0.2

Request #13246 Caching of stat entries
Submitted: 2008-02-28 09:53 UTC Modified: 2008-06-19 01:51 UTC
From: mbaierl Assigned:
Status: Open Package: HTTP_WebDAV_Client (version 1.0.0)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2008-02-28 09:53 UTC] mbaierl (Michael Baierl)
Description: ------------ Right now it is very slow to issue a HTTP request for each stat call - and the data is loaded in dir_opendir anyways, so it should be cached there as well. Code should look something like this hack: $currenturl = ""; $buffer = ""; $GLOBALS['__webdavstat__'] = array(); // for all returned resource entries foreach (split("\n", $req->getResponseBody()) as $line) { // get the href URL if (ereg("href>([^<]*)", $line, $matches)) { // skip the directory itself if ($matches[1] != $this->path) { // just remember the basenames to return them later with readdir() $this->dirfiles[] = basename($matches[1]); } $currenturl = basename($matches[1]); } $buffer .= $line."\n"; if( ereg("^<D:response ", $line, $matches)) { // start of response, ensure buffer is empty $buffer = $line."\n"; } if( ereg("</D:response>", $line, $matches)) { // we are done, parse it $propinfo = &new HTTP_WebDAV_Client_parse_propfind_response2($buffer); $GLOBALS['__webdavstat__'][$path.$currenturl] = $propinfo->stat(); unset($propinfo); $buffer = ""; } } The HTTP_WebDAV_Client_parse_propfind_response2 class is a changed version of the existing HTTP_WebDAV_Client_parse_propfind_response class and the data is stored in a global variable until the next directory is read - this ensures PHP is not running out of memory for large scripts.

Comments

 [2008-06-19 01:38 UTC] kawai (Hiroaki Kawai)
-1 to this. Because cache should be under the control of clearstatcache().
 [2008-06-19 01:51 UTC] mbaierl (Michael Baierl)
Hi Kawai, theoretically I fully agree with you; but you should not compare traditional file systems with WebDAV - each stat request for WebDAV requires a severe amount of time, depending on the Internet connection and server location i.e. 500ms. Now if you open and traverse a directory with only a few hundred files this sums up to quite some time and also the protocol overhead sums up. Furthermore you are reading the data a second time, separately for each entry - which does not make sense as you already loaded the exactly same data for *all* entries when you executed the open_dir in the first place. In my experience this significantly speeds up directory traversals using WebDAV.