448191 Posted May 25, 2007 Share Posted May 25, 2007 I recently looked at the php://memory and php://temp wrappers, but I fail to see the use of it. I was hoping (idle hope) these would persist across requests, so I could utilize them for session management, but it gets terminated with execution environment of each request, so no go. Anybody has any idea how these wrappers might be useful? Quote Link to comment https://forums.phpfreaks.com/topic/52950-phpmemory-wrapper/ Share on other sites More sharing options...
448191 Posted May 25, 2008 Author Share Posted May 25, 2008 Hah. Came across this ancient post and decided to answer my own question. I've recently found a use for these wrappers: to use with file manipulation functions. Example: /** * Private string parser for factory method * * @param string $string * @param string $delimiter * @param string $enclosure * * @return array */ private static function _parseString($string, $delimiter, $enclosure) { $maxMemAllocation = 2 * 1024 * 1024; $handle = fopen("php://temp/maxmemory:$maxMemAllocation", 'r+'); fwrite($handle, $string); rewind($handle); $rows = array(); while(false !== ($row = fgetcsv($handle, null, $delimiter, $enclosure))) { $rows[] = $row; } $keys = array_shift($rows); foreach($rows as $row) { $assocRows[] = array_combine($keys, $row); } return $assocRows; } There's no string counterpart of fgetcsv (str_getcsv is only in CVS), so this saves me a little trouble not having to write csv parsing code, with hardly any performance loss, possibly none. Quote Link to comment https://forums.phpfreaks.com/topic/52950-phpmemory-wrapper/#findComment-549794 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.