Emulating ASP's Application object with php

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
samscripts
Forum Commoner
Posts: 57
Joined: Tue Apr 23, 2002 4:34 pm
Location: London, UK

Emulating ASP's Application object with php

Post by samscripts »

Hi, just wondering if anyone had tried to emulate the only thing i like about asp - the application object thing that lets you set a variable that can be accessed from all scripts?

I'm trying it myself using a little class that reads itself from a specific file at the beginning of the script and then serialises itself to the file on script termination, and was wondering if anyone else had tried anything similar they wanted to share?

For anyone interested, the basic usage is like this (more or less)

Code: Select all

<?php

/* include the application class - not shown here because it is currently somewhere in between concept and code  */

include("application.class.php");

$application = new application();

if( !isset($application->counter ) ){
   $application->counter = 1;
}else{
   $application->counter++;
}

echo "This server has served ".$application->counter." requests for scripts using application object";

?>
this example would just count how many times pages were requested - useless i know but meant as an illustration of how to use the class.

If anyone has tried something similar, I'd love to hear about it.

cheers, Sam
User avatar
phpPete
Forum Commoner
Posts: 97
Joined: Sun Aug 18, 2002 4:40 pm
Location: New Jersey

Post by phpPete »

Sorry...spoke to soon...found this article you might find interesting:
http://www.tapinternet.com/index.php/ne ... event=view
Last edited by phpPete on Mon Sep 02, 2002 10:33 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

the application-object is not bound to a session. Every script of the same application (server) can share the data stored in .application
edit: hmm..this post became useless ;)
Last edited by volka on Mon Sep 02, 2002 11:22 pm, edited 1 time in total.
mgkimsal
Forum Newbie
Posts: 7
Joined: Wed May 22, 2002 12:16 pm

tap internet article

Post by mgkimsal »

I wrote that piece - I'd suggest following it's model of writing things to a database instead of serializing to a file. Let the database handle concurrency issues with data storage - don't try to solve it in your script if you can avoid it. Let me know if you have any questions. :)
Post Reply