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

Bug #4229 Stream_Var needs url_stat method
Submitted: 2005-04-27 00:24 UTC
From: ahayes Assigned: ahayes
Status: Closed Package: Stream_Var
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 30 + 14 = ?

 
 [2005-04-27 00:24 UTC] ahayes
Description: ------------ The Stream_Var package should have a url_stat method. This is needed as otherwise attempts to make file_exist calls (amongst others) will fail. It already has a stream_stat method, so url_stat could almost be an extension of this method. Reproduce code: --------------- require_once "Stream/Var.php"; stream_wrapper_register("var", "Stream_Var"); $GLOBALS['somefile'] = 'blah blah blah'; if(!file_exists("var://GLOBALS/somefile")) { die('The file does not exist'); } echo "file exists"; Expected result: ---------------- file exists Actual result: -------------- Actual result would be "The file does not exist" To fix this something as simple as: /** * return information about the stream * * @access public * @return array $stat information about the stream (currently only the length is included) */ function url_stat() { $stat = $this->stream_stat(); $stat[7] = $stat['size']; return $stat; } Would most likely do, however it would be nice if we actually checked that the variable had been defined with isset in stream_stat.

Comments

 [2005-11-04 02:30 UTC] ahayes
I have modified the url_stat method I previously submitted so that it looks as follows: =========>8=========== /** * This method is called in response to stat() calls on the URL paths * * @see http://au.php.net/stream_wrapper_register * @author Alex Hayes <ahayes@wcg.net.au> */ function url_stat($path, $flags) { $time = time() - $process['times']['stime']; $keys = array( 'dev' => 0, 'ino' => 0, 'mode' => 33216, // chmod 700, so the web user has read, write and execute on the file 'nlink' => 0, 'uid' => posix_getuid(), // this processes uid 'gid' => posix_getgid(), // this processes uid 'rdev' => 0, 'size' => strlen($this->_pointer), 'atime' => $time, 'mtime' => $time, 'ctime' => $time, 'blksize' => 0, 'blocks' => 0 ); return array_merge(array_values($keys), $keys); } =========8<=========== This has not been tested extensively however it does work with is_readable and file_exists.
 [2005-11-04 02:33 UTC] ahayes
Note however when using file_size() it does not seem to be able to find $this->_pointer This is caused as for some reason, the call to file_size does not seem to call the constructor for Stream_Var. This to me would point to an error to do with PHP streams but I'm yet to chase this down.
 [2006-08-23 01:13 UTC] ahayes at php dot net (Alex Hayes)
Note, for anyone requiring this functionality, you can use the following class. This has been tested on PHP5 only, and things like file_size do not seem to work properly (as stated in the inline docs) ============8<============== <?php require_once "Stream/Var.php"; // {{{ class SOAP_Fault_Util /** * Provides url_stat capabilities to Stream_Var * * Until this functionality exists in Stream_Var (see ticket * http://pear.php.net/bugs/bug.php?id=4229) you can use this class to gain access * to the url_stat methods that are needed by certain functions that utilise streams. * * Note however, for instance the fact that file_size does not * seem to report properly, as url_stat can't seem to find $this->_pointer * * @category Stream * @package Stream_Var_Stat * @version 0.1.0 * @author Alex Hayes <ahayes@wcg.net.au> */ class Stream_Var_Stat extends Stream_Var { /** * This method is called in response to stat() calls on the URL paths * * As taken from the PHP Manual: * * "This method is called in response to stat() calls on the URL paths * associated with the wrapper and should return as many elements in * common with the system function as possible. Unknown or unavailable * values should be set to a rational value (usually 0)." * * With regards to the implementation that is Stream_Var we can actually fake * some of the data. For instance, the uid and gid can be that of the corrent * posix_getuid and posix_getgid() * * The following outlines the information that we essentially fake: * * - dev set to 0 * - ino set to 0 * - mode set to 33216 (chmod 700 means user has read, write and execute on the file) * - nlink set to 0 * - uid if the method posix_getuid exist, this is called, otherwise 0 is returned * - gid if the method posix_getgid exist, this is called, otherwise 0 is returned * - rdev set to 0 * - size is set to the strlen of the pointer. * - atime set to current value returned by time() * - mtime set to current value returned by time() * - ctime set to current value returned by time() * - blksize 0 * - blocks 0 * * @param string $path * * @see http://au.php.net/stream_wrapper_register * @author Alex Hayes <ahayes@wcg.net.au> */ function url_stat($path, $flags) { $time = time(); $keys = array( 'dev' => 0, 'ino' => 0, 'mode' => 33216, // chmod 700 means user has read, write and execute on the file 'nlink' => 0, 'uid' => function_exists('posix_getuid') ? posix_getuid() : 0, // this processes uid 'gid' => function_exists('posix_getgid') ? posix_getgid() : 0, // this processes uid 'rdev' => 0, 'size' => $flags & STREAM_URL_STAT_QUIET ? @strlen($this->_pointer) : strlen($this->_pointer), 'atime' => $time, 'mtime' => $time, 'ctime' => $time, 'blksize' => 0, 'blocks' => 0 ); return array_merge(array_values($keys), $keys); } } // }}} ?> ============>8==============
 [2006-08-23 01:29 UTC] ahayes at php dot net (Alex Hayes)
Please use this class instead of the one placed in previous comment (slight documentation fixes only). Note that this will mean that you will need to replace all occurances of Stream_Var with Stream_Var_Stat. This code is essentially in alpha state (hence the version number). It has been tested, but not unit tested. Its intention is just to get you by until a proper solution exists within Stream_Var. ============8<============== <?php require_once "Stream/Var.php"; // {{{ class Stream_Var_Stat /** * Provides url_stat capabilities to Stream_Var * * Until this functionality exists in Stream_Var (see ticket * http://pear.php.net/bugs/bug.php?id=4229) you can use * this class to gain access to the url_stat methods that * are needed by certain functions that utilise streams. * * Note however, for instance the fact that file_size does not * seem to report properly, as url_stat can't seem to find * $this->_pointer * * @category Stream * @package Stream_Var_Stat * @version 0.1.0 * @author Alex Hayes <ahayes@wcg.net.au> */ class Stream_Var_Stat extends Stream_Var { /** * This method is called in response to stat() calls on the URL paths * * As taken from the PHP Manual: * * "This method is called in response to stat() calls on the URL paths * associated with the wrapper and should return as many elements in * common with the system function as possible. Unknown or unavailable * values should be set to a rational value (usually 0)." * * With regards to the implementation that is Stream_Var we can actually fake * some of the data. For instance, the uid and gid can be that of the corrent * posix_getuid and posix_getgid() * * The following outlines the information that we essentially fake: * * - 'dev': is unknown and set to 0 * - 'ino': is unknown and set to 0 * - 'mode': set to 33216 (chmod 700 means user has read, write and execute on the file) * - 'nlink': is unknown and set to 0 * - 'uid': if the method posix_getuid exist, this is called, otherwise 0 is returned * - 'gid': if the method posix_getgid exist, this is called, otherwise 0 is returned * - 'rdev' unknown and set to 0 * - 'size': is set to the strlen of the pointer. * - 'atime': set to current value returned by time() * - 'mtime': set to current value returned by time() * - 'ctime': set to current value returned by time() * - 'blksize': is unknown and set to 0 * - 'blocks': is unknown and set to 0 * * @param string $path The path to stat. * @param integer $flags Holds additional flags set by the streams API. * It can hold one or more of the following values * OR'd together. * - STREAM_URL_STAT_LINK - currently this is * ignored. * - STREAM_URL_STAT_QUIET - makes call to * strlen quiet * * @return array * * @see http://au.php.net/stream_wrapper_register * @author Alex Hayes <ahayes@wcg.net.au> */ function url_stat($path, $flags) { $time = time(); $keys = array( 'dev' => 0, 'ino' => 0, 'mode' => 33216, // chmod 700 means user has read, write and execute on the file 'nlink' => 0, 'uid' => function_exists('posix_getuid') ? posix_getuid() : 0, // this processes uid 'gid' => function_exists('posix_getgid') ? posix_getgid() : 0, // this processes uid 'rdev' => 0, 'size' => $flags & STREAM_URL_STAT_QUIET ? @strlen($this->_pointer) : strlen($this->_pointer), 'atime' => $time, 'mtime' => $time, 'ctime' => $time, 'blksize' => 0, 'blocks' => 0 ); return array_merge(array_values($keys), $keys); } } // }}} ?> ============>8==============
 [2007-07-06 16:15 UTC] cweiske (Christian Weiske)
Could someone fix this please?
 [2009-08-12 12:52 UTC] cweiske (Christian Weiske)
-Status: Assigned +Status: Closed -Assigned To: schst +Assigned To: ahayes
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/get/ Fixed in version 1.1.0