473,473 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Application Scope variables ?

aa
I am migrating to PHP from ASP where there are the Application Scope variables which are accessible from any page on a website and which are used, in particular, for hit counters.
Is there a similar mechanism in PHP?

Jul 17 '05 #1
33 15826
aa wrote:
I am migrating to PHP from ASP where there are the Application Scope
variables which are accessible from any page on a website and which are
used, in particular, for hit counters.
Is there a similar mechanism in PHP?


Hi,

Yes there is, take a look at sessions:
http://nl3.php.net/manual/en/ref.session.php

Regards,
Ruben.
Jul 17 '05 #2
Dear Virgil,

your thinking is still too influenced by the rigid ASP structure.
Relax, open your mind and RTFM on sessions. :-)
Best Regards,

Lucas

"Virgil Green" <vj*@DESPAMobsydian.com> wrote in message news:<Cn******************@newssvr30.news.prodigy. com>...
"Ruben van Engelenburg" <ruben@NOSPAM!.nl> wrote in message
news:41***********************@news.xs4all.nl...
aa wrote:
I am migrating to PHP from ASP where there are the Application Scope
variables which are accessible from any page on a website and which are
used, in particular, for hit counters.
Is there a similar mechanism in PHP?


Hi,

Yes there is, take a look at sessions:
http://nl3.php.net/manual/en/ref.session.php


Sessions are not the same as application scope, I don't believe.

I've seen references to shared memory schemes, but they are avaialble to the
entire computer, not just a single application (all sessions running under
the same site id, for example).

- Virgil

Jul 17 '05 #3
> your thinking is still too influenced by the rigid ASP structure.
Relax, open your mind and RTFM on sessions. :-)


Session variables are not the same as application-level variables. ASP
offers an application framework, ASP *is* the framework.

Having said that, you can replicate functionality via PHP by either using
common files for variable storage/retrieval, or using a database. Some info
should be easily locatable by searching.
Jul 17 '05 #4
aa
Thanks.
You mean that PHP does not allow to store application-level variables in
memory and every time I need to modify such a variable I have to retrieve it
from disc (a file or DB) and then to write it back?

"Zurab Davitiani" <ag*@mindless.com> wrote in message
news:AL******************@newssvr27.news.prodigy.c om...
your thinking is still too influenced by the rigid ASP structure.
Relax, open your mind and RTFM on sessions. :-)
Session variables are not the same as application-level variables. ASP
offers an application framework, ASP *is* the framework.

Having said that, you can replicate functionality via PHP by either using
common files for variable storage/retrieval, or using a database. Some

info should be easily locatable by searching.

Jul 17 '05 #5

"aa" <aa@virgin.net> wrote in message
news:41***********************@ptn-nntp-reader04.plus.net...
Thanks.
You mean that PHP does not allow to store application-level variables in
memory and every time I need to modify such a variable I have to retrieve
it
from disc (a file or DB) and then to write it back?
If you want to store variables between one page and another the PHP way is
sessions. All you need is session_start() at the beginning of each script.
This will create an empty $_SESSION array the first time, then give you back
everything you put in it.

Note that you do not have to write the session data out to file manually as
PHP will do it automatically for you at the end of the script. It's all in
the manual.

--
Tony Marston

http://www.tonymarston.net
"Zurab Davitiani" <ag*@mindless.com> wrote in message
news:AL******************@newssvr27.news.prodigy.c om...
> your thinking is still too influenced by the rigid ASP structure.
> Relax, open your mind and RTFM on sessions. :-)


Session variables are not the same as application-level variables. ASP
offers an application framework, ASP *is* the framework.

Having said that, you can replicate functionality via PHP by either using
common files for variable storage/retrieval, or using a database. Some

info
should be easily locatable by searching.


Jul 17 '05 #6
aa wrote:
Thanks.
You mean that PHP does not allow to store application-level variables in
memory and every time I need to modify such a variable I have to retrieve it
from disc (a file or DB) and then to write it back?


That's the case. However I've found from experience that the only real
application globals needed are configuration parameters. These are
probably best loaded from a flat file as the application shouldn't be
changing them in the first place. Including a config file is fairly low
overhead in php.

If you need global variables then the simplest method is to save them in
a DB table. The overhead of retrieving these should be minimal as DB
servers should cache regular queries.
Jul 17 '05 #7
Dear Zurab,

sessions are stored as common files on the web server, one can
configure it accordingly to his/her needs so that data(variables) are
accesible from the required scope. Is there anything I missed?
Best Regards,

Lucas
Zurab Davitiani <ag*@mindless.com> wrote in message news:<AL******************@newssvr27.news.prodigy. com>...
your thinking is still too influenced by the rigid ASP structure.
Relax, open your mind and RTFM on sessions. :-)


Session variables are not the same as application-level variables. ASP
offers an application framework, ASP *is* the framework.

Having said that, you can replicate functionality via PHP by either using
common files for variable storage/retrieval, or using a database. Some info
should be easily locatable by searching.

Jul 17 '05 #8
"Lucas" <th******@directbox.com> wrote in message
news:fd*************************@posting.google.co m...
Dear Virgil,

your thinking is still too influenced by the rigid ASP structure.
Relax, open your mind and RTFM on sessions. :-)


I'm hardly influenced by ASP structure. I've never worked in ASP. I've read
the PHP manual sections on sessions many times before.

Please, enlighten me. Explain to me how sessions could be used to provide
the equivalent of application-scoped variables in ASP. The closest thing I
see is by sharing session IDs. That, of course, is a hack. There would be
nothing by default to synchronize access between multiple requests, so each
request could start with the same session info, update it and then spend
time merrily writing over each others changes. I could write my own custom
save handler, but I believe that writing such a handler to manage multiple
sessions as a single "session" would violate the spirit of the session and
lead to a maintenance nightmare.

I look forward to the details of your strategy.

- Virgil
Jul 17 '05 #9
aa
Session will only make such a variable available within this session.
But I am talking about a variable available from any page from any session

"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message
news:ci*******************@news.demon.co.uk...

"aa" <aa@virgin.net> wrote in message
news:41***********************@ptn-nntp-reader04.plus.net...
Thanks.
You mean that PHP does not allow to store application-level variables in
memory and every time I need to modify such a variable I have to retrieve it
from disc (a file or DB) and then to write it back?
If you want to store variables between one page and another the PHP way is
sessions. All you need is session_start() at the beginning of each script.
This will create an empty $_SESSION array the first time, then give you

back everything you put in it.

Note that you do not have to write the session data out to file manually as PHP will do it automatically for you at the end of the script. It's all in
the manual.

--
Tony Marston

http://www.tonymarston.net
"Zurab Davitiani" <ag*@mindless.com> wrote in message
news:AL******************@newssvr27.news.prodigy.c om...
> your thinking is still too influenced by the rigid ASP structure.
> Relax, open your mind and RTFM on sessions. :-)

Session variables are not the same as application-level variables. ASP
offers an application framework, ASP *is* the framework.

Having said that, you can replicate functionality via PHP by either using common files for variable storage/retrieval, or using a database. Some

info
should be easily locatable by searching.



Jul 17 '05 #10
aa
"sessions are stored as common files on the web server"

Lucas,

1. Do these "common files" keep sitting on the disk after the relevant
session expired?
2. If they do, then for how long?
3. And how they might be accessed from another session?
Even if they can be accessable, I have difficulties to see a practical use
of them unless you keep track of every session file which is a tedious task

"Lucas" <th******@directbox.com> wrote in message
news:fd**************************@posting.google.c om...
Dear Zurab,

sessions are stored as common files on the web server, one can
configure it accordingly to his/her needs so that data(variables) are
accesible from the required scope. Is there anything I missed?
Best Regards,

Lucas
Zurab Davitiani <ag*@mindless.com> wrote in message

news:<AL******************@newssvr27.news.prodigy. com>...
your thinking is still too influenced by the rigid ASP structure.
Relax, open your mind and RTFM on sessions. :-)


Session variables are not the same as application-level variables. ASP
offers an application framework, ASP *is* the framework.

Having said that, you can replicate functionality via PHP by either using common files for variable storage/retrieval, or using a database. Some info should be easily locatable by searching.

Jul 17 '05 #11
aa
Just to stream the discussion up - how a page hit conter in implemented in PHP?
In ASP you increment a relative Application scope variable every time a page is requested. This veraible is accessible from any session.
This variable is sitting in the memory as long as the Application (i.e. the website) is running.
If the Application is stopped, it fires an event "application_on_close" and on this event you write an application data to a file from which it can be recovered when the application is restarted.

How do I get the same effect in PHP?
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader01.plus.net...
I am migrating to PHP from ASP where there are the Application Scope variables which are accessible from any page on a website and which are used, in particular, for hit counters.
Is there a similar mechanism in PHP?

Jul 17 '05 #12

"aa" <aa@virgin.net> wrote in message
news:41***********************@ptn-nntp-reader04.plus.net...
"sessions are stored as common files on the web server"

Lucas,

1. Do these "common files" keep sitting on the disk after the relevant
session expired?
2. If they do, then for how long?
3. And how they might be accessed from another session?
Even if they can be accessable, I have difficulties to see a practical use
of them unless you keep track of every session file which is a tedious

task

1. The Session management part of PHP cleans them up regularly.
2. Depends upon your settings in php.ini.
3. By using the same session ID for multiple "sessions"

And I find it highly impractical to attempt to use them constructively in
this manner. Better to understand this part of sessions to allow you to be
more careful when it comes to securing them. If one doesn't have cookies
enabled, one merely needs to put the appropriate variable=value in your URL
to hijaack a session.

- Virgil
Jul 17 '05 #13

"aa" <aa@virgin.net> wrote in message
news:41***********************@ptn-nntp-reader04.plus.net...
Session will only make such a variable available within this session.
But I am talking about a variable available from any page from any session
Then do what other people have already suggested:
(a) Store those variables in a database.
(b) Use a configuration which you can include() in every script.

There are no application-level variables in PHP which persist across pages
and sessions, so get used to it.

--
Tony Marston

http://www.tonymarston.net
"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message
news:ci*******************@news.demon.co.uk...

"aa" <aa@virgin.net> wrote in message
news:41***********************@ptn-nntp-reader04.plus.net...
> Thanks.
> You mean that PHP does not allow to store application-level variables
> in
> memory and every time I need to modify such a variable I have to retrieve > it
> from disc (a file or DB) and then to write it back?


If you want to store variables between one page and another the PHP way
is
sessions. All you need is session_start() at the beginning of each
script.
This will create an empty $_SESSION array the first time, then give you

back
everything you put in it.

Note that you do not have to write the session data out to file manually

as
PHP will do it automatically for you at the end of the script. It's all
in
the manual.

--
Tony Marston

http://www.tonymarston.net
> "Zurab Davitiani" <ag*@mindless.com> wrote in message
> news:AL******************@newssvr27.news.prodigy.c om...
>> > your thinking is still too influenced by the rigid ASP structure.
>> > Relax, open your mind and RTFM on sessions. :-)
>>
>> Session variables are not the same as application-level variables. ASP
>> offers an application framework, ASP *is* the framework.
>>
>> Having said that, you can replicate functionality via PHP by either using >> common files for variable storage/retrieval, or using a database. Some
> info
>> should be easily locatable by searching.
>
>



Jul 17 '05 #14

"Virgil Green" <vj*@DESPAMobsydian.com> wrote in message
news:if**************@newssvr11.news.prodigy.com.. .
"Lucas" <th******@directbox.com> wrote in message
news:fd*************************@posting.google.co m...
Dear Virgil,

your thinking is still too influenced by the rigid ASP structure.
Relax, open your mind and RTFM on sessions. :-)
I'm hardly influenced by ASP structure. I've never worked in ASP. I've
read
the PHP manual sections on sessions many times before.

Please, enlighten me. Explain to me how sessions could be used to provide
the equivalent of application-scoped variables in ASP.


Store these variables in a database, or in a configuration file which you
can include() in every script.

PHP does not have any equivalent to application-scoped variables in ASP.

--
Tony Marston

http://www.tonymarston.net
The closest thing I
see is by sharing session IDs. That, of course, is a hack. There would be
nothing by default to synchronize access between multiple requests, so
each
request could start with the same session info, update it and then spend
time merrily writing over each others changes. I could write my own custom
save handler, but I believe that writing such a handler to manage multiple
sessions as a single "session" would violate the spirit of the session and
lead to a maintenance nightmare.

I look forward to the details of your strategy.

- Virgil

Jul 17 '05 #15
To implement a hit counter in PHP I would use a database table.

There is no such thing as being able to detect when the application is closed. The client simply stops sending requests to your web site. Is he still reading the last page? Has he jumped to another site? Has he closed the browser? That is impossible to tell.

--
Tony Marston

http://www.tonymarston.net
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader04.plus.net...
Just to stream the discussion up - how a page hit conter in implemented in PHP?
In ASP you increment a relative Application scope variable every time a page is requested. This veraible is accessible from any session.
This variable is sitting in the memory as long as the Application (i.e. the website) is running.
If the Application is stopped, it fires an event "application_on_close" and on this event you write an application data to a file from which it can be recovered when the application is restarted.

How do I get the same effect in PHP?
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader01.plus.net...
I am migrating to PHP from ASP where there are the Application Scope variables which are accessible from any page on a website and which are used, in particular, for hit counters.
Is there a similar mechanism in PHP?

Jul 17 '05 #16
aa <> wrote:
Just to stream the discussion up - how a page hit conter in implemented in PHP? 8< -- snip -- >8 How do I get the same effect in PHP?

You have to save the new value in a file/database/... whenever you changed
it, since there is no variable scope valid for more than the current
session. At least not in standard PHP, maybe there is a non-standard
extension for this.

You might even have to check the synchronisation, for example using file
locks to prevent two scripts from reading the same data file at the same
time.

If you use a database you should increment using
"SET counter = counter + 1"
instead of
"SET counter = " . ($count + 1)

--
Simon Stienen <http://dangerouscat.net> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #17
>Just to stream the discussion up - how a page hit conter in implemented in PHP?

I'd use a database:
UPDATE hit_count set count=count+1, last=now() where url='...';
or if I really wanted details for each hit, add an entry to a hit_log table,
logging time, URL, and perhaps other stuff like IP, user name, session, referrer, etc.
In ASP you increment a relative Application scope variable every time a page is
requested. This veraible is accessible from any session.
Besides hit counters, of what *USE* is such a variable?
It can be accessed from (and messed up by) so many different
concurrent sessions that any significant read/write use will have
to worry about locking issues. Does ASP even guarantee that several
sessions each doing the equivalent of $hitcount++; will be atomic
and not lose counts (on a multiprocessor machine, possibly)?

Assume $last_server is the ID of the last waitperson assigned to a table (and
it's one of those "Application-scope" variables.
IDs run from 1 to $max_server. You want to assign them in turn, round-robin.

$last_server++;
if ($last_server > $max_server) { $last_server = 1; }
$this_server = $last_server;
.... assign $this_server to serve the food for this order ...

Now, how do you write that (or its equivalent in ASP) so it's
multi-session, multi-processor safe? You don't assign the same
server two orders a row. You don't skip anyone. Not even if a bunch
of orders come in simultaneously.
I also wouldn't be too pleased to learn that I'd lose several days
worth of changes to that variable (kept only in memory) if the
machine crashed. In particular, losing a variable like 'next invoice
number to assign' kept in memory only would be a real nuisance.
This variable is sitting in the memory as long as the Application (i.e. the website) is
running.
Which means you can lose it at any time if the Application is running.
If the Application is stopped, it fires an event "application_on_close" and on this
event you write an application data to a file from which it can be recovered when the
application is restarted.
And if the application, or system, crashes? How often do you actually intentionally
shut down a web server (besides applying security patches)? In my experience, this
is MUCH less often than CPU fan failure or power supply failure.
How do I get the same effect in PHP?


What do you need it for? I think it makes an unreliable hit counter and it's not
good for much else.

Gordon L. Burditt
Jul 17 '05 #18
In article <41***********************@ptn-nntp-reader04.plus.net>, aa wrote:
Just to stream the discussion up - how a page hit conter in implemented =
in PHP?


Imho there is a better solution for this. Use the logging
functionalities of your webserver. And write a script, in the language
of your choice to display those data.
--
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #19
In article <41***********************@ptn-nntp-reader01.plus.net>, aa wrote:
I am migrating to PHP from ASP where there are the Application Scope =
variables which are accessible from any page on a website and which are =
used, in particular, for hit counters.


Store the data yourself in a file (serialize) /database/memory (shmop) and you have
your own flexible shared variables.

--
Tim Van Wassenhove <http://www.timvw.info>
Jul 17 '05 #20
>To implement a hit counter in PHP I would use a database table.

Agreed.
There is no such thing as being able to detect when the application is closed. The
client simply stops sending requests to your web site. Is he still reading the last
page? Has he jumped to another site? Has he closed the browser? That is impossible to
tell.


That's a SESSION, not the application. And no, you can't tell when
it's closed except by timeout or occasionally by someone clicking
on "LOG OUT".

The APPLICATION being referred to is the web server itself. Shutting
it down might be done with commands like "apachectl stop" or
"shutdown", or tripping over the power cord. In my experience when
the web server is shut down, it is shut down quite rudely by CPU
fan failure, more than 50% of the time.

Gordon L. Burditt

Jul 17 '05 #21
aa
"Does ASP even guarantee that several sessions each doing the equivalent of
$hitcount++; "

ASP' application is an object with a method "lock" to handle attempts to
change a variable from two or more sessions at a time. I do not know is it
guaranties something, but it works.
So if there is nothing like that in PHP - thanks - you saved me time lokinmg
for something which is not there.
"Gordon Burditt" <go***********@burditt.org> wrote in message
news:ci********@library2.airnews.net...
Just to stream the discussion up - how a page hit conter in implemented in PHP?

I'd use a database:
UPDATE hit_count set count=count+1, last=now() where url='...';
or if I really wanted details for each hit, add an entry to a hit_log table, logging time, URL, and perhaps other stuff like IP, user name, session, referrer, etc.
In ASP you increment a relative Application scope variable every time a
page isrequested. This veraible is accessible from any session.


Besides hit counters, of what *USE* is such a variable?
It can be accessed from (and messed up by) so many different
concurrent sessions that any significant read/write use will have
to worry about locking issues. Does ASP even guarantee that several
sessions each doing the equivalent of $hitcount++; will be atomic
and not lose counts (on a multiprocessor machine, possibly)?

Assume $last_server is the ID of the last waitperson assigned to a table

(and it's one of those "Application-scope" variables.
IDs run from 1 to $max_server. You want to assign them in turn, round-robin.
$last_server++;
if ($last_server > $max_server) { $last_server = 1; }
$this_server = $last_server;
... assign $this_server to serve the food for this order ...

Now, how do you write that (or its equivalent in ASP) so it's
multi-session, multi-processor safe? You don't assign the same
server two orders a row. You don't skip anyone. Not even if a bunch
of orders come in simultaneously.
I also wouldn't be too pleased to learn that I'd lose several days
worth of changes to that variable (kept only in memory) if the
machine crashed. In particular, losing a variable like 'next invoice
number to assign' kept in memory only would be a real nuisance.
This variable is sitting in the memory as long as the Application (i.e. the website) isrunning.
Which means you can lose it at any time if the Application is running.
If the Application is stopped, it fires an event "application_on_close" and on thisevent you write an application data to a file from which it can be recovered when theapplication is restarted.


And if the application, or system, crashes? How often do you actually

intentionally shut down a web server (besides applying security patches)? In my experience, this is MUCH less often than CPU fan failure or power supply failure.
How do I get the same effect in PHP?
What do you need it for? I think it makes an unreliable hit counter and

it's not good for much else.

Gordon L. Burditt

Jul 17 '05 #22
aa
> Then do what other people have already suggested:

Actually I have suggested that myself, but hoped that there is more elegant
solution
Thanks.

"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message
news:ci*******************@news.demon.co.uk...

"aa" <aa@virgin.net> wrote in message
news:41***********************@ptn-nntp-reader04.plus.net...
Session will only make such a variable available within this session.
But I am talking about a variable available from any page from any session

Then do what other people have already suggested:
(a) Store those variables in a database.
(b) Use a configuration which you can include() in every script.

There are no application-level variables in PHP which persist across pages
and sessions, so get used to it.

--
Tony Marston

http://www.tonymarston.net
"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message
news:ci*******************@news.demon.co.uk...

"aa" <aa@virgin.net> wrote in message
news:41***********************@ptn-nntp-reader04.plus.net...
> Thanks.
> You mean that PHP does not allow to store application-level variables
> in
> memory and every time I need to modify such a variable I have to

retrieve
> it
> from disc (a file or DB) and then to write it back?

If you want to store variables between one page and another the PHP way
is
sessions. All you need is session_start() at the beginning of each
script.
This will create an empty $_SESSION array the first time, then give you

back
everything you put in it.

Note that you do not have to write the session data out to file manually as
PHP will do it automatically for you at the end of the script. It's all
in
the manual.

--
Tony Marston

http://www.tonymarston.net

> "Zurab Davitiani" <ag*@mindless.com> wrote in message
> news:AL******************@newssvr27.news.prodigy.c om...
>> > your thinking is still too influenced by the rigid ASP structure.
>> > Relax, open your mind and RTFM on sessions. :-)
>>
>> Session variables are not the same as application-level variables.

ASP >> offers an application framework, ASP *is* the framework.
>>
>> Having said that, you can replicate functionality via PHP by either

using
>> common files for variable storage/retrieval, or using a database. Some > info
>> should be easily locatable by searching.
>
>



Jul 17 '05 #23
aa
"There is no such thing as being able to detect when the application is closed.The client simply stops sending requests to your web site. Is he still reading the last page? Has he jumped to another site? Has he closed the browser?
That is impossible to tell."

That is not necessary to tell, for the actions of a particular visitor are not relevant.
As it happens with Windows/IIS/ASP, Application can either be closed manually, or it times out if there are not requests for a preset period of time. In other words, application closes when the last active session times out.
Is this the case with Apache server?
"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message news:ci*******************@news.demon.co.uk...
To implement a hit counter in PHP I would use a database table.

There is no such thing as being able to detect when the application is closed. The client simply stops sending requests to your web site. Is he still reading the last page? Has he jumped to another site? Has he closed the browser? That is impossible to tell.

--
Tony Marston

http://www.tonymarston.net
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader04.plus.net...
Just to stream the discussion up - how a page hit conter in implemented in PHP?
In ASP you increment a relative Application scope variable every time a page is requested. This veraible is accessible from any session.
This variable is sitting in the memory as long as the Application (i.e. the website) is running.
If the Application is stopped, it fires an event "application_on_close" and on this event you write an application data to a file from which it can be recovered when the application is restarted.

How do I get the same effect in PHP?
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader01.plus.net...
I am migrating to PHP from ASP where there are the Application Scope variables which are accessible from any page on a website and which are used, in particular, for hit counters.
Is there a similar mechanism in PHP?

Jul 17 '05 #24
If by "application" you mean "web server" then it is not common practice to stop the web server when the last client has finished. A web server usually runs 24/7 so that it is available whenever somebody wants to access it. If you are talking about a closed application such as on a company's intranet which may only be available during certain times of day then shutting down the web server does nothing more than shut down the web server. There is no concept of running any closedown routines for whatever application may have been accessed during the time the web server was running. A web server like Apache is merely a vehicle for servicing HTTP requests. It serves up html documents or php documents or whatever. Those documents are the application. It has no knowledge of any particular application which it may run. Why should it?

--
Tony Marston

http://www.tonymarston.net
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader02.plus.net...
"There is no such thing as being able to detect when the application is closed.The client simply stops sending requests to your web site. Is he still reading the last page? Has he jumped to another site? Has he closed the browser?
That is impossible to tell."

That is not necessary to tell, for the actions of a particular visitor are not relevant.
As it happens with Windows/IIS/ASP, Application can either be closed manually, or it times out if there are not requests for a preset period of time. In other words, application closes when the last active session times out.
Is this the case with Apache server?
"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message news:ci*******************@news.demon.co.uk...
To implement a hit counter in PHP I would use a database table.

There is no such thing as being able to detect when the application is closed. The client simply stops sending requests to your web site. Is he still reading the last page? Has he jumped to another site? Has he closed the browser? That is impossible to tell.

--
Tony Marston

http://www.tonymarston.net
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader04.plus.net...
Just to stream the discussion up - how a page hit conter in implemented in PHP?
In ASP you increment a relative Application scope variable every time a page is requested. This veraible is accessible from any session.
This variable is sitting in the memory as long as the Application (i.e. the website) is running.
If the Application is stopped, it fires an event "application_on_close" and on this event you write an application data to a file from which it can be recovered when the application is restarted.

How do I get the same effect in PHP?
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader01.plus.net...
I am migrating to PHP from ASP where there are the Application Scope variables which are accessible from any page on a website and which are used, in particular, for hit counters.
Is there a similar mechanism in PHP?

Jul 17 '05 #25
Lucas wrote:
sessions are stored as common files on the web server, one can
configure it accordingly to his/her needs so that data(variables) are
accesible from the required scope. Is there anything I missed?


Yes. Application level variables in this case means that the variables are
shared within the defined frame of an application. i.e. the variables are
shared between different sessions or clients accessing the "application."
For more information, look up Application and Session objects within the
ASP framework; or even Java servlets.
Jul 17 '05 #26

"Zurab Davitiani" <ag*@mindless.com> wrote in message
news:Nl***************@newssvr14.news.prodigy.com. ..
Lucas wrote:
sessions are stored as common files on the web server, one can
configure it accordingly to his/her needs so that data(variables) are
accesible from the required scope. Is there anything I missed?


Yes. Application level variables in this case means that the variables are
shared within the defined frame of an application. i.e. the variables are
shared between different sessions or clients accessing the "application."
For more information, look up Application and Session objects within the
ASP framework; or even Java servlets.


This is a PHP group, so references to ASP and Java are out of place.

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #27
Tony Marston wrote:
This is a PHP group, so references to ASP and Java are out of place.


They are relevant if you read the discussion thread as they pertain to the
discussion on how to replicate similar functionality in PHP.
Jul 17 '05 #28
aa
You missed me, Tony. Of course I did not mean application==webserver
"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message news:ci*******************@news.demon.co.uk...
If by "application" you mean "web server" then it is not common practice to stop the web server when the last client has finished. A web server usually runs 24/7 so that it is available whenever somebody wants to access it. If you are talking about a closed application such as on a company's intranet which may only be available during certain times of day then shutting down the web server does nothing more than shut down the web server. There is no concept of running any closedown routines for whatever application may have been accessed during the time the web server was running. A web server like Apache is merely a vehicle for servicing HTTP requests. It serves up html documents or php documents or whatever. Those documents are the application. It has no knowledge of any particular application which it may run. Why should it?

--
Tony Marston

http://www.tonymarston.net
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader02.plus.net...
"There is no such thing as being able to detect when the application is closed.The client simply stops sending requests to your web site. Is he still reading the last page? Has he jumped to another site? Has he closed the browser?
That is impossible to tell."

That is not necessary to tell, for the actions of a particular visitor are not relevant.
As it happens with Windows/IIS/ASP, Application can either be closed manually, or it times out if there are not requests for a preset period of time. In other words, application closes when the last active session times out.
Is this the case with Apache server?
"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message news:ci*******************@news.demon.co.uk...
To implement a hit counter in PHP I would use a database table.

There is no such thing as being able to detect when the application is closed. The client simply stops sending requests to your web site. Is he still reading the last page? Has he jumped to another site? Has he closed the browser? That is impossible to tell.

--
Tony Marston

http://www.tonymarston.net
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader04.plus.net...
Just to stream the discussion up - how a page hit conter in implemented in PHP?
In ASP you increment a relative Application scope variable every time a page is requested. This veraible is accessible from any session.
This variable is sitting in the memory as long as the Application (i.e. the website) is running.
If the Application is stopped, it fires an event "application_on_close" and on this event you write an application data to a file from which it can be recovered when the application is restarted.

How do I get the same effect in PHP?
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader01.plus.net...
I am migrating to PHP from ASP where there are the Application Scope variables which are accessible from any page on a website and which are used, in particular, for hit counters.
Is there a similar mechanism in PHP?

Jul 17 '05 #29
Hi aa,

"aa" <aa@virgin.net> wrote in message news:<41***********************@ptn-nntp-reader04.plus.net>...
Session will only make such a variable available within this session.
But I am talking about a variable available from any page from any session
using real sessions(!=cookie emulation) makes it possible to access
data from any client application, independent of the one that created
it. However, I did read some stuff on ALV, and admit it's much more
sophisticated, does anyone know if there are any improvements in PHP5?

"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message
news:ci*******************@news.demon.co.uk...

"aa" <aa@virgin.net> wrote in message
news:41***********************@ptn-nntp-reader04.plus.net...
Thanks.
You mean that PHP does not allow to store application-level variables in
memory and every time I need to modify such a variable I have to retrieve it
from disc (a file or DB) and then to write it back?


If you want to store variables between one page and another the PHP way is
sessions. All you need is session_start() at the beginning of each script.
This will create an empty $_SESSION array the first time, then give you

back
everything you put in it.

Note that you do not have to write the session data out to file manually

as
PHP will do it automatically for you at the end of the script. It's all in
the manual.

--
Tony Marston

http://www.tonymarston.net
"Zurab Davitiani" <ag*@mindless.com> wrote in message
news:AL******************@newssvr27.news.prodigy.c om...
> > your thinking is still too influenced by the rigid ASP structure.
> > Relax, open your mind and RTFM on sessions. :-)
>
> Session variables are not the same as application-level variables. ASP
> offers an application framework, ASP *is* the framework.
>
> Having said that, you can replicate functionality via PHP by either using> common files for variable storage/retrieval, or using a database. Some info> should be easily locatable by searching.


Jul 17 '05 #30
Then the answer is easy. Apache has no concept of an "application". It is simply a web server which waits for requests and issues responses. PHP also has no concept of an "application" in the way you describe for IIS/ASP. However, you can achieve the same functionality by using config files, sessions, and/or databases.

--
Tony Marston

http://www.tonymarston.net
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader01.plus.net...
You missed me, Tony. Of course I did not mean application==webserver
"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message news:ci*******************@news.demon.co.uk...
If by "application" you mean "web server" then it is not common practice to stop the web server when the last client has finished. A web server usually runs 24/7 so that it is available whenever somebody wants to access it. If you are talking about a closed application such as on a company's intranet which may only be available during certain times of day then shutting down the web server does nothing more than shut down the web server. There is no concept of running any closedown routines for whatever application may have been accessed during the time the web server was running. A web server like Apache is merely a vehicle for servicing HTTP requests. It serves up html documents or php documents or whatever. Those documents are the application. It has no knowledge of any particular application which it may run. Why should it?

--
Tony Marston

http://www.tonymarston.net
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader02.plus.net...
"There is no such thing as being able to detect when the application is closed.The client simply stops sending requests to your web site. Is he still reading the last page? Has he jumped to another site? Has he closed the browser?
That is impossible to tell."

That is not necessary to tell, for the actions of a particular visitor are not relevant.
As it happens with Windows/IIS/ASP, Application can either be closed manually, or it times out if there are not requests for a preset period of time. In other words, application closes when the last active session times out.
Is this the case with Apache server?
"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message news:ci*******************@news.demon.co.uk...
To implement a hit counter in PHP I would use a database table.

There is no such thing as being able to detect when the application is closed. The client simply stops sending requests to your web site. Is he still reading the last page? Has he jumped to another site? Has he closed the browser? That is impossible to tell.

--
Tony Marston

http://www.tonymarston.net
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader04.plus.net...
Just to stream the discussion up - how a page hit conter in implemented in PHP?
In ASP you increment a relative Application scope variable every time a page is requested. This veraible is accessible from any session.
This variable is sitting in the memory as long as the Application (i.e. the website) is running.
If the Application is stopped, it fires an event "application_on_close" and on this event you write an application data to a file from which it can be recovered when the application is restarted.

How do I get the same effect in PHP?
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader01.plus.net...
I am migrating to PHP from ASP where there are the Application Scope variables which are accessible from any page on a website and which are used, in particular, for hit counters.
Is there a similar mechanism in PHP?

Jul 17 '05 #31
.oO(Tony Marston)
[...]


Is it one of OE's many "features" to answer to an HTML-posting in HTML
instead of plain text?

It's not really funny having to download a bloated 305-lines posting
(thanks to the HTML) with just 4 lines of new text.

Fup2 poster

Micha
Jul 17 '05 #32
aa
In ASP an application is an object created when a first request is made to a website. This object seats in the memory and contains methods and properties some of the properties can be created and modified from ASP code.
As a websever can serve more them one website and some websites might be visited just several times a day, there is little point to keep all these website objects in the memory all the time. For that purpose, if a website does not receive requestes for certain time (which can be preset on the websrver), the Application object is destroyed and memory reclaimed. Not to loose data stored in the Object, it allows to write this data onto disk before being destroyed.
If I understand correctly, PHP does not maintain such an object and the variables relevant to the whole website need to be written onto disk before a relevant session expires.

"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message news:ci*******************@news.demon.co.uk...
Then the answer is easy. Apache has no concept of an "application". It is simply a web server which waits for requests and issues responses. PHP also has no concept of an "application" in the way you describe for IIS/ASP. However, you can achieve the same functionality by using config files, sessions, and/or databases.

--
Tony Marston

http://www.tonymarston.net
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader01.plus.net...
You missed me, Tony. Of course I did not mean application==webserver
"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message news:ci*******************@news.demon.co.uk...
If by "application" you mean "web server" then it is not common practice to stop the web server when the last client has finished. A web server usually runs 24/7 so that it is available whenever somebody wants to access it. If you are talking about a closed application such as on a company's intranet which may only be available during certain times of day then shutting down the web server does nothing more than shut down the web server. There is no concept of running any closedown routines for whatever application may have been accessed during the time the web server was running. A web server like Apache is merely a vehicle for servicing HTTP requests. It serves up html documents or php documents or whatever. Those documents are the application. It has no knowledge of any particular application which it may run. Why should it?

--
Tony Marston

http://www.tonymarston.net
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader02.plus.net...
"There is no such thing as being able to detect when the application is closed.The client simply stops sending requests to your web site. Is he still reading the last page? Has he jumped to another site? Has he closed the browser?
That is impossible to tell."

That is not necessary to tell, for the actions of a particular visitor are not relevant.
As it happens with Windows/IIS/ASP, Application can either be closed manually, or it times out if there are not requests for a preset period of time. In other words, application closes when the last active session times out.
Is this the case with Apache server?
"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message news:ci*******************@news.demon.co.uk...
To implement a hit counter in PHP I would use a database table.

There is no such thing as being able to detect when the application is closed. The client simply stops sending requests to your web site. Is he still reading the last page? Has he jumped to another site? Has he closed the browser? That is impossible to tell.

--
Tony Marston

http://www.tonymarston.net
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader04.plus.net...
Just to stream the discussion up - how a page hit conter in implemented in PHP?
In ASP you increment a relative Application scope variable every time a page is requested. This veraible is accessible from any session.
This variable is sitting in the memory as long as the Application (i.e. the website) is running.
If the Application is stopped, it fires an event "application_on_close" and on this event you write an application data to a file from which it can be recovered when the application is restarted.

How do I get the same effect in PHP?
"aa" <aa@virgin.net> wrote in message news:41***********************@ptn-nntp-reader01.plus.net...
I am migrating to PHP from ASP where there are the Application Scope variables which are accessible from any page on a website and which are used, in particular, for hit counters.
Is there a similar mechanism in PHP?

Jul 17 '05 #33

"aa" <aa@virgin.net> wrote in message
news:41***********************@ptn-nntp-reader02.plus.net...
In ASP an application is an object created when a first request is made to
a
website. This object seats in the memory and contains methods and
properties
some of the properties can be created and modified from ASP code.
As a websever can serve more them one website and some websites might be
visited just several times a day, there is little point to keep all these
website objects in the memory all the time. For that purpose, if a website
does not receive requests for certain time (which can be preset on the
websrver), the Application object is destroyed and memory reclaimed. Not
to
loose data stored in the Object, it allows to write this data onto disk
before being destroyed.
If I understand correctly, PHP does not maintain such an object and the
variables relevant to the whole website need to be written onto disk
before
a relevant session expires.


Correct. PHP does not understand the concept of "application" as you
describe it.

From your description it seems to be more of a function of the web server as
only the web server can create the object on the first request, and destroy
the object if there have not been any requests for a period of time.

If you want to emulate this with PHP you must read in the variables with
every request and write out any changes before the script dies. You can use
session files or database tables. It may be possible to use data in shared
memory, but you would have to write your own routines for loading it and
destroying it. Personally I wouldn't bother as the overhead of reading in
data with every request is so small that it's not worth the effort to
replace it with something more flashy.

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #34

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hal Vaughan | last post by:
Being self taught, this is one thing I've always had trouble with -- I finally get it straight in one situation and I find I'm not sure about another. I have a class that keeps calling an...
4
by: BB | last post by:
Hello all, I might be missing something here, but am trying to understand the difference between using application-level variables--i.e. Application("MyVar")--and global variables--i.e. public...
20
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business...
7
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
3
by: rdemyan via AccessMonster.com | last post by:
Sometimes users (including myself) accidentally click on the application close icon in the application menu bar when they meant to just click on the 'X' for the form. Of course the app closes and...
0
by: ellon | last post by:
I found a good way to do that: <?php function application_start (){ global $_APP; global $shm_id; $shm_id = shmop_open(0xff3, "c", 0644, 10000); $shm_size = shmop_size($shm_id); ...
11
by: Sylvia A. | last post by:
How can I define global classes in web application ? Classes can be set to session variables ? Thanks
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
0
MMcCarthy
by: MMcCarthy | last post by:
We often get questions on this site that refer to the scope of variables and where and how they are declared. This tutorial is intended to cover the basics of variable scope in VBA for MS Access. For...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.