In: <11************ **********@g14g 2000cwa.googleg roups.com>, "vishal" <vi************ @yahoo.co.in> wrote:
can i implement some lock mechanism so that this global variable is not
accessed by more than one application at some time which may create
some confusion.
One of the things I regard as usually an asset, but sometimes a weakness is that
there is no way to store global, application wide variables the way you can
in java servlets. Part of this is the way php programs are parsed and run
each time the page is loaded. Variables don't hang around after. The other part
is the way fork() works.
With mod_perl you can "sort of" share variables, but they only apply to the current
process. (For this reason, synchronization is not an issue)
On a UNIX platform, have a look at:
http://us4.php.net/manual/en/ref.sem.php http://us4.php.net/shmop
As far as I know, (hopefully someone will correct me if I'm wrong) this is the
only way to share _memory_.
I've used shared memory in other applications (other languages) and
generally recommend against it if at all possible. It can lead to a
royal nuisance when it's time to free them. Maybe things have changed,
maybe I was doing something wrong, but the shared memory was "leaked"
when the program was terminated abruptly.
Consider using a database, file, or even the serialize stuff for persistant
storage, it's slower but unless you require the speed, it's safer.
For obvious reasons, shared memory doesn't work across servers, so, if your
page is ever served via multiple web servers, (load balancing, etc..) it
won't work.
Jamie
--
http://www.geniegate.com Custom web programming
gu******@lnubb. pbz (rot13) User Management Solutions