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:
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;
?>
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