Page 1 of 1

PHP vs. ASP (global.asa???)

Posted: Thu Sep 12, 2002 7:59 am
by duda_y
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

Posted: Thu Sep 12, 2002 8:01 am
by twigletmac
Recent thread on the same topic:
http://www.devnetwork.net/forums/viewtopic.php?t=2891

Mac

Posted: Thu Sep 12, 2002 12:45 pm
by samscripts
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

Posted: Thu Sep 12, 2002 3:27 pm
by jason
samscripts: Hrm... http://www.samscripts.com/scripts/application_object doesn't show up very well in Mozilla..the Example is all foobared.

Posted: Fri Sep 13, 2002 6:10 am
by samscripts
thanks for letting me know Jason, just checked it out.

foobared is a bit of an understatement :oops:

thanks, Sam