'; } return $rs; } $meta = false; $meta = fgetcsv($fp, 32000, ","); if (!$meta) { fclose($fp); $err = "Unexpected EOF 1"; return $false; } } // Get Column definitions $flds = array(); foreach($meta as $o) { $o2 = explode(':',$o); if (sizeof($o2)!=3) { $arr[] = $meta; $flds = false; break; } $fld = new ADOFieldObject(); $fld->name = urldecode($o2[0]); $fld->type = $o2[1]; $fld->max_length = $o2[2]; $flds[] = $fld; } } else { fclose($fp); $err = "Recordset had unexpected EOF 2"; return $false; } // slurp in the data $MAXSIZE = 128000; $text = ''; while ($txt = fread($fp,$MAXSIZE)) { $text .= $txt; } fclose($fp); @$arr = unserialize($text); //var_dump($arr); if (!is_array($arr)) { $err = "Recordset had unexpected EOF (in serialized recordset)"; if (get_magic_quotes_runtime()) $err .= ". Magic Quotes Runtime should be disabled!"; return $false; } $rs = new $rsclass(); $rs->timeCreated = $ttl; $rs->InitArrayFields($arr,$flds); return $rs; } /** * Save a file $filename and its $contents (normally for caching) with file locking * Returns true if ok, false if fopen/fwrite error, 0 if rename error (eg. file is locked) */ function adodb_write_file($filename, $contents,$debug=false) { # http://www.php.net/bugs.php?id=9203 Bug that flock fails on Windows # So to simulate locking, we assume that rename is an atomic operation. # First we delete $filename, then we create a $tempfile write to it and # rename to the desired $filename. If the rename works, then we successfully # modified the file exclusively. # What a stupid need - having to simulate locking. # Risks: # 1. $tempfile name is not unique -- very very low # 2. unlink($filename) fails -- ok, rename will fail # 3. adodb reads stale file because unlink fails -- ok, $rs timeout occurs # 4. another process creates $filename between unlink() and rename() -- ok, rename() fails and cache updated if (strncmp(PHP_OS,'WIN',3) === 0) { // skip the decimal place $mtime = substr(str_replace(' ','_',microtime()),2); // getmypid() actually returns 0 on Win98 - never mind! $tmpname = $filename.uniqid($mtime).getmypid(); if (!($fd = @fopen($tmpname,'w'))) return false; if (fwrite($fd,$contents)) $ok = true; else $ok = false; fclose($fd); if ($ok) { @chmod($tmpname,0644); // the tricky moment @unlink($filename); if (!@rename($tmpname,$filename)) { @unlink($tmpname); $ok = 0; } if (!$ok) { if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed')); } } return $ok; } if (!($fd = @fopen($filename, 'a'))) return false; if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) { if (fwrite( $fd, $contents )) $ok = true; else $ok = false; fclose($fd); @chmod($filename,0644); }else { fclose($fd); if ($debug)ADOConnection::outp( " Failed acquiring lock for $filename\n"); $ok = false; } return $ok; }