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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
duda_y
Forum Newbie
Posts: 6
Joined: Mon Sep 02, 2002 10:39 am
Location: Argentina

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

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Recent thread on the same topic:
http://www.devnetwork.net/forums/viewtopic.php?t=2891

Mac
samscripts
Forum Commoner
Posts: 57
Joined: Tue Apr 23, 2002 4:34 pm
Location: London, UK

Post 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
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

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

Post by samscripts »

thanks for letting me know Jason, just checked it out.

foobared is a bit of an understatement :oops:

thanks, Sam
Post Reply