Is there something similar to global.asa of ASP in PHP.
Need application scope variables, and would be happy
if had Application On Start and Session On Start events
or something similar. Could not find this in manual.
Thanks
PHP vs. ASP (global.asa???)
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
samscripts
- Forum Commoner
- Posts: 57
- Joined: Tue Apr 23, 2002 4:34 pm
- Location: London, UK
Hi, I was trying to get something to work along these lines. The small class mentioned in this thread is a good way to deal with it, but there is a problem of what happens if one script reads the data, modifies it, and stores the changes, and another script does the same.
ie. script 1 reads file:
script 2 reads file:
script 1 changes variable
script 1 saves changes
script 2 changes variable, or adds a new variable, or whatever
script 2 saves changes
results in the changes by script 1 getting lost.
I've got a class here that tries to get around this problem by using the flock function, but it also requires you to only access the variables in a specific way, ie:
Between the call to open("w") and the call to close(), any other scripts trying to access it will have to wait, but it was the best I could come up with.
Oh, and I haven't tested it a huge amount either, so I can only say that 'theoretically' it works.
There's a simple example of it in action here.
Enough of my inane ramblings, hope this helps,
Sam
ie. script 1 reads file:
script 2 reads file:
script 1 changes variable
script 1 saves changes
script 2 changes variable, or adds a new variable, or whatever
script 2 saves changes
results in the changes by script 1 getting lost.
I've got a class here that tries to get around this problem by using the flock function, but it also requires you to only access the variables in a specific way, ie:
Code: Select all
<?php
$app = new applicationobject("appdatafilename");
$app->open("w"); // open the object to write to
$app->counter++;
$app->close();
echo "The value of the counter is ".$app->counter;
?>Oh, and I haven't tested it a huge amount either, so I can only say that 'theoretically' it works.
There's a simple example of it in action here.
Enough of my inane ramblings, hope this helps,
Sam
samscripts: Hrm... http://www.samscripts.com/scripts/application_object doesn't show up very well in Mozilla..the Example is all foobared.
-
samscripts
- Forum Commoner
- Posts: 57
- Joined: Tue Apr 23, 2002 4:34 pm
- Location: London, UK