Re: sessions and passing variables
| From: | rarmin | Date: | Mon, 08 Apr 2002 14:31:51 +0000 |
| Subject: | Re: sessions and passing variables | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-92051@lists.php.net to get a copy of this message | ||
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: <?php $strData = serialize($data); $fp = fopen("globalObjectData.inc", "w"); fwrite($fp, $strData); fclose($fp); ?> Code for accessing: <?php // 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