mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
Upgraded to ADOdb 4.5.1. Contains a lot of small fixes and speed-ups.
This commit is contained in:
parent
f5f346a594
commit
fab7e07e19
90 changed files with 1555 additions and 832 deletions
|
@ -7,7 +7,7 @@ global $ADODB_INCLUDED_CSV;
|
|||
$ADODB_INCLUDED_CSV = 1;
|
||||
|
||||
/*
|
||||
V4.50 6 July 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
V4.51 29 July 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence. See License.txt.
|
||||
|
@ -249,4 +249,56 @@ $ADODB_INCLUDED_CSV = 1;
|
|||
$rs->InitArrayFields($arr,$flds);
|
||||
return $rs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save a file $filename and its $contents (normally for caching) with file locking
|
||||
*/
|
||||
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,'a'))) return false;
|
||||
$ok = ftruncate($fd,0);
|
||||
if (!fwrite($fd,$contents)) $ok = false;
|
||||
fclose($fd);
|
||||
chmod($tmpname,0644);
|
||||
// the tricky moment
|
||||
@unlink($filename);
|
||||
if (!@rename($tmpname,$filename)) {
|
||||
unlink($tmpname);
|
||||
$ok = false;
|
||||
}
|
||||
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)) {
|
||||
$ok = fwrite( $fd, $contents );
|
||||
fclose($fd);
|
||||
chmod($filename,0644);
|
||||
}else {
|
||||
fclose($fd);
|
||||
if ($debug)ADOConnection::outp( " Failed acquiring lock for $filename<br>\n");
|
||||
$ok = false;
|
||||
}
|
||||
|
||||
return $ok;
|
||||
}
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue