Re: domDoc class uses flock()
| From: | Terence | Date: | Mon, 05 May 2003 11:27:12 +0000 |
| Subject: | Re: domDoc class uses flock() | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-1260@lists.php.net to get a copy of this message | ||
There are two other methods I should have included (which explains why I haven't closed the resource in DOMDOC_AS_WRITEFILE mode.
I realise this question is borderline internals/general but no one in the user community seems to be equipped to answer it for me. I appologies if I have made an error in this judgement.
/**
* mass storage serialisation
*
* This function will dump the textual contents of the DOM document (in it's
* current state to) file.
*
* @param uri path to destination file
* @return bool success or failure
*/
function Commit() {
if($this->mode == DOMDOC_AS_WRITEFILE) {
fwrite($this->fp,$this->xmlGetDoc());
flock($this->fp,LOCK_UN);
fclose($this->fp);
}
else {
return $this->objErr->throw(
"Commit() can only be used when domDoc is invoked in "
."DOMDOC_AS_WRITEFILE mode"
);
}
return true;
}
/**
* mass storage serialisation
*
* This function will dump the textual contents of the DOM document (in it's
* current state to) a specified file.
*
* @param uri path to destination file
* @return bool success or failure
*/
function CommitToFile($uriDestination) {
$fp = fopen($uriDestination,"w+")
or $this->objErr->throw("CommitToFile: could not open ".$uriDestination." for writing");
flock($fp,LOCK_EX);
fwrite($fp,$this->xmlGetDoc())
or $this->objErr->throw("CommitToFile: could write to ".$uriDestination);
flock($fp,LOCK_UN);
fclose($fp);
return true;
}