Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:1258 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92017 invoked by uid 1007); 5 May 2003 11:19:40 -0000 Message-ID: <20030505111940.92012.qmail@pb1.pair.com> To: internals@lists.php.net Date: Mon, 05 May 2003 21:20:15 +1000 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 References: <1051831866.2944.10.camel@hemna.uh.nu> <20030505110212.72298.qmail@pb1.pair.com> In-Reply-To: <20030505110212.72298.qmail@pb1.pair.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 203.37.117.98 Subject: domDoc class uses flock() From: tk.lists@fastmail.fm (Terence) I'v already started developing an object wrapper to DOM XML for my own usage (but freely available to anyone as with all my stuff) which provides a central point where I can control the way all this file accessing is done. Here is the constructor method alone plus the constant definitions preceeding the class. This code has not been tested yet. /** * Constructor method * * Create the objDoc instance property and associated ndRoot property based * on the user-selected mode of document creation. In the process, establish * the blnIsReadOnly property. * * @param mixed information required to create a DOM document * @param int constant specifying how the document is to be created * @return void */ function domDoc(&$Starter,$intUse = DOMDOC_AS_NEW) { $this->objErr = new xmlErrorLog($this); $this->intMode = $intUse; $this->blnIsReadOnly = true; // for more info on each case block, see // comments in the constant definitions // at the top of this file. switch ($intUse) { case DOMDOC_AS_NEW: $this->blnIsReadOnly = false; $this->objDoc = domxml_new_doc("1.0"); $elRoot = $this->objDoc->create_element($Starter); $this->ndRoot = $this->objDoc->append_child($elRoot); break; case DOMDOC_AS_READFILE: $fp = fopen($Starter,"r") OR $this->objErr->throw( "could not open ".$Starter." for reading." ); // attempt thread safety by using flock flock($fp,LOCK_SH); $xmlData = fread($fp,filesize($Starter)); flock($fp,LOCK_UN); fclose($fp); // finish working with the file as // quickly as possible and THEN worry // about making a DOM doc from it. $this->_domOpenFromData($xmlData); break; case DOMDOC_AS_WRITEFILE: $this->blnIsReadOnly = false; $this->fp = fopen($Starter,"bw+") OR $this->objErr->throw( "could not open ".$Starter." for writing." ); flock($this->fp,LOCK_EX); $xmlData = fread($this->fp,filesize($Starter)); $this->_domOpenFromData($xmlData); break; case DOMDOC_AS_REMOTEFILE: $fp = fopen($Starter,"r") OR $this->objErr->throw( "could not open ".$Starter." for reading." ); $xmlData = fread($fp,filesize($Starter)); fclose($fp); $this->_domOpenFromData($xmlData); break; case DOMDOC_AS_REFERENCE: $this->objDoc =& $Starter; break; case DOMDOC_AS_DATA: $this->_domOpenFromData($Starter); break; default: $this->objErr->throw( "second argument to domDoc constructor is invalid" ); } }