Connecting Tech Pros Worldwide Forums | Help | Site Map

sharing information across requests

Antony Sequeira
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi

I needed to share some configuration information across requests.
The most straightforward way would be code it in a php file and include it
in every other script.
The problem with this approach is, the configuration script is executed on
every request.
The configuration data once figured out by the script remains the same for a
host, but the script to figure out the data could be arbitrarily complex.
The only mechanism I have figured out so far is to use the
shm_attach ,shm_get_var etc functions to store a single php array with all
my config in sysv shared memory.
So, the code to figure out the config runs only once and then populates the
shared mem, after that in every request, the config is read from the shared
memory.

Is this the only way to do this stuff (the main reason for my posting here)
?
Essentially I am looking for something like a static member data in java
which would stay up as long as the class is loaded (which would be across
arbitrary number of requests). For example any java servlet class. The php
static stuff goes away after each request.
I was hoping that stuffing things into $_SERVER would retain things across
requests. No such luck.

Is there a better solution than the SysV shared mem api.
-Antony

P.S. I am using 4.3.4 apache 2.x and 1.x on linux (Fedora Core 3)



Kevin
Guest
 
Posts: n/a
#2: Jul 17 '05

re: sharing information across requests


Can you serialize the configuration data into a database or text file?

- Kevin

"Antony Sequeira" <usemyfullname@hotmail.com> wrote in message
news:Mf_Gd.2835$8Z1.906@newssvr14.news.prodigy.com ...[color=blue]
> Hi
>
> I needed to share some configuration information across requests.
> The most straightforward way would be code it in a php file and include it
> in every other script.
> The problem with this approach is, the configuration script is executed on
> every request.
> The configuration data once figured out by the script remains the same for
> a host, but the script to figure out the data could be arbitrarily
> complex.
> The only mechanism I have figured out so far is to use the
> shm_attach ,shm_get_var etc functions to store a single php array with all
> my config in sysv shared memory.
> So, the code to figure out the config runs only once and then populates
> the shared mem, after that in every request, the config is read from the
> shared memory.
>
> Is this the only way to do this stuff (the main reason for my posting
> here) ?
> Essentially I am looking for something like a static member data in java
> which would stay up as long as the class is loaded (which would be across
> arbitrary number of requests). For example any java servlet class. The php
> static stuff goes away after each request.
> I was hoping that stuffing things into $_SERVER would retain things across
> requests. No such luck.
>
> Is there a better solution than the SysV shared mem api.
> -Antony
>
> P.S. I am using 4.3.4 apache 2.x and 1.x on linux (Fedora Core 3)
>[/color]


Jan Pieter Kunst
Guest
 
Posts: n/a
#3: Jul 17 '05

re: sharing information across requests


Antony Sequeira wrote:[color=blue]
> Hi
>
> I needed to share some configuration information across requests.
> The most straightforward way would be code it in a php file and include it
> in every other script.
> The problem with this approach is, the configuration script is executed on
> every request.[/color]

That is what I do. I resigned myself to the fact that in a stateless web
application every request basically restarts the whole application all
over again (apart from possible persistent $_SESSION variables).

A few years ago I attended a talk about persistent PHP objects (it was
called "PHP Bananas", very clever, supposed to be the PHP version of
"Java Beans" if I understood things correctly), something that could
help to get more 'state' in web apps, but I don't know if that project
is still active or how far they got.
[color=blue]
> The only mechanism I have figured out so far is to use the
> shm_attach ,shm_get_var etc functions to store a single php array with all
> my config in sysv shared memory.[/color]

I'm not familiar with those functions. Wouldn't a session also work in
your case (since you are only storing an array)?

JP


--
Sorry, <devnull@cauce.org> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
Michael Fesser
Guest
 
Posts: n/a
#4: Jul 17 '05

re: sharing information across requests


.oO(Antony Sequeira)
[color=blue]
>Essentially I am looking for something like a static member data in java
>which would stay up as long as the class is loaded (which would be across
>arbitrary number of requests). For example any java servlet class. The php
>static stuff goes away after each request.
>I was hoping that stuffing things into $_SERVER would retain things across
>requests. No such luck.[/color]

This question was asked few weeks ago. See this thread for some answers:

where do you store app wide data?
http://groups.google.com/groups?thre...1.iinet.net.au

Micha
Closed Thread


Similar PHP bytes