"Rarmin" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I have one question about operations that can be done with XML.
> What I need to do is build a web site which stores some data in XML
> files and retrieve that data. It's basically the system that allows
> users to register, login and upload and download some files. It needs to
>   use XML.
>
> The question is:
> If there are simultaneos approaches to register or upload (registration
> and upload data are all stored in the single XML file), using DOM will
> make me problems. DOM loads the whole document into memory, and writes
> it whole to disk. The question is how to avoid this? Since if, for
> example, two users register at the same time, they both get their copy
> of document, and the later that writes itself to the file will overwrite
> the changes made by the first one. How to avoid this and still use DOM?
> I am using PHP 4.1.2 and libxml 2.4.19.
>
> Any advice is wellcome.
> Tnx in advance.
>
> Armin
>

You could lock the xml file while a user registers:
http://www.php.net/manual/en/function.flock.php

if ($fp = fopen($file, "r")) {
    if (flock ($fp, LOCK_EX + LOCK_NB )) {
        // process registration here
        flock ($fp,LOCK_UN);
        fclose($fp);
    }
}

however only one user will be able to register at a time.

It would be better to store this in a database because then you can have
multiple simultaneous registrations. Then when whatever application needs to
see the info as xml, have php generate the xml from the data in the
database.

Peter



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to