[PHP] PHP and DOM XML
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] sessions and passing variables
Is there a way to pass variables (objects) across the different sessions. I thought of sharing one object for all users that access my web site (it's an object that does some operations with files common to all users, like reading and writing). Any ideas? Tnx in advance. Armin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: sessions and passing variables
Michael Virnstein wrote: > you also have to make sure, that only one user can access the file for > writing at one time, or your data gets probably > screwed. The easiest way would be storing the object not in a file but in a > database, so you don't have to care about locking. Tnx for the help, and one more question. If I would serialize object and store it in a file, I would need some way to implement object waiting at the locked file untill it's unlocked (some kind of semaphore or monitor). I can lock the file with flock, but I don't know how to put object "on hold" while the file it's requesting is locked. As for the database, I don't use database (it's an assignment that needs to be done using XML, so all data is in XML files) and I don't see much sence in using db for storing only one serialized object. > > But do you really need the same instance of the object? why not simply > perform a $obj =& new Class(); If I figure out how to put "on hold" object while some other object performs it's operations on locked file, I wouldn't need to use the same instance. > > > -- > Code for Storing: > > $strData = serialize($data); > > $fp = fopen("globalObjectData.inc", "w"); > fwrite($fp, $strData); > fclose($fp); > > ?> > > Code for accessing: > > > // include object source before unserializing > include "myObjectSrc.php"; > > $fp = fopen("globalObjectData.inc", "w"); > $strData = fread($fp, filesize("globalObjectData.inc")); > fclose($fp); > > // so we have our object back > $obj = unserialize($strData); > > > Does anyone know how to implement monitor or semaphore or waiting queue on file resource? I'm using PHP 4.1.2 and Apache 1.2.23 on Windows platform. Armin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] file locks
Is there a way for a script to tell if the file it's trying to access is locked by other script (via flock()) or not. I need to make script wait untill other script running in a parallel thread releases the lock on the file. Tnx in advance. Armin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file locks
Liam Gibbs wrote: > < trying to access is locked by other script (via > flock()) or not. I need to make script wait untill > other script running in a parallel thread releases the > lock on the file.>> > > Without testing, would this work? Just a suggestion > (read: shot in the dark) that may work. > > while(!$filehandle) { >$filehandle = @fopen("file_in_question", > "r/w/whatever"); > } > > > <> > > You're welcome in advance. :) > > > __ > Do You Yahoo!? > Yahoo! Tax Center - online filing with TurboTax > http://taxes.yahoo.com/ How is it possible that the file locked with exclusive lock can be opened by another call to fopen in the same script? Am i getting it all wrong, or the second call to fopen in the next code should fail? $fp=fopen("somefile", "w"); flock($fp, LOCK_EX); $fp1=fopen("somefile", "w"); I'm using php 4.1.2 windows version on apache 1.2.23. Armin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php