Application Scope variables ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • aa

    Application Scope variables ?

    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?

  • Ruben van Engelenburg

    #2
    Re: Application Scope variables ?

    aa wrote:[color=blue]
    > 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?[/color]

    Hi,

    Yes there is, take a look at sessions:


    Regards,
    Ruben.

    Comment

    • Lucas

      #3
      Re: Application Scope variables ?

      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" <vjg@DESPAMobsy dian.com> wrote in message news:<CnE3d.126 58$yp2.5590@new ssvr30.news.pro digy.com>...[color=blue]
      > "Ruben van Engelenburg" <ruben@NOSPAM!. nl> wrote in message
      > news:414ebb56$0 $65124$e4fe514c @news.xs4all.nl ...[color=green]
      > > aa wrote:[color=darkred]
      > > > 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?[/color]
      > >
      > > Hi,
      > >
      > > Yes there is, take a look at sessions:
      > > http://nl3.php.net/manual/en/ref.session.php[/color]
      >
      > 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[/color]

      Comment

      • Zurab Davitiani

        #4
        Re: Application Scope variables ?

        > your thinking is still too influenced by the rigid ASP structure.[color=blue]
        > Relax, open your mind and RTFM on sessions. :-)[/color]

        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.

        Comment

        • aa

          #5
          Re: Application Scope variables ?

          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" <agt@mindless.c om> wrote in message
          news:ALJ3d.2175 9$Lf5.2677@news svr27.news.prod igy.com...[color=blue][color=green]
          > > your thinking is still too influenced by the rigid ASP structure.
          > > Relax, open your mind and RTFM on sessions. :-)[/color]
          >
          > 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[/color]
          info[color=blue]
          > should be easily locatable by searching.[/color]


          Comment

          • Tony Marston

            #6
            Re: Application Scope variables ?


            "aa" <aa@virgin.ne t> wrote in message
            news:415002f7$0 $42212$ed2e19e4 @ptn-nntp-reader04.plus.n et...[color=blue]
            > 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?[/color]

            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

            This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL



            [color=blue]
            > "Zurab Davitiani" <agt@mindless.c om> wrote in message
            > news:ALJ3d.2175 9$Lf5.2677@news svr27.news.prod igy.com...[color=green][color=darkred]
            >> > your thinking is still too influenced by the rigid ASP structure.
            >> > Relax, open your mind and RTFM on sessions. :-)[/color]
            >>
            >> 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[/color]
            > info[color=green]
            >> should be easily locatable by searching.[/color]
            >
            >[/color]


            Comment

            • Kevin Thorpe

              #7
              Re: Application Scope variables ?

              aa wrote:[color=blue]
              > 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?[/color]

              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.

              Comment

              • Lucas

                #8
                Re: Application Scope variables ?

                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 <agt@mindless.c om> wrote in message news:<ALJ3d.217 59$Lf5.2677@new ssvr27.news.pro digy.com>...[color=blue][color=green]
                > > your thinking is still too influenced by the rigid ASP structure.
                > > Relax, open your mind and RTFM on sessions. :-)[/color]
                >
                > 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.[/color]

                Comment

                • Virgil Green

                  #9
                  Re: Application Scope variables ?

                  "Lucas" <thelucas@direc tbox.com> wrote in message
                  news:fdb66b30.0 409201432.a2501 59@posting.goog le.com...[color=blue]
                  > Dear Virgil,
                  >
                  > your thinking is still too influenced by the rigid ASP structure.
                  > Relax, open your mind and RTFM on sessions. :-)[/color]

                  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


                  Comment

                  • aa

                    #10
                    Re: Application Scope variables ?

                    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" <tony@NOSPAM.de mon.co.uk> wrote in message
                    news:cip0pa$ig4 $1$8300dec7@new s.demon.co.uk.. .[color=blue]
                    >
                    > "aa" <aa@virgin.ne t> wrote in message
                    > news:415002f7$0 $42212$ed2e19e4 @ptn-nntp-reader04.plus.n et...[color=green]
                    > > 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[/color][/color]
                    retrieve[color=blue][color=green]
                    > > it
                    > > from disc (a file or DB) and then to write it back?[/color]
                    >
                    > 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[/color]
                    back[color=blue]
                    > everything you put in it.
                    >
                    > Note that you do not have to write the session data out to file manually[/color]
                    as[color=blue]
                    > 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
                    >
                    >
                    >[color=green]
                    > > "Zurab Davitiani" <agt@mindless.c om> wrote in message
                    > > news:ALJ3d.2175 9$Lf5.2677@news svr27.news.prod igy.com...[color=darkred]
                    > >> > 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[/color][/color][/color]
                    using[color=blue][color=green][color=darkred]
                    > >> common files for variable storage/retrieval, or using a database. Some[/color]
                    > > info[color=darkred]
                    > >> should be easily locatable by searching.[/color]
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • aa

                      #11
                      Re: Application Scope variables ?

                      "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" <thelucas@direc tbox.com> wrote in message
                      news:fdb66b30.0 409202352.6263a c6f@posting.goo gle.com...[color=blue]
                      > 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 <agt@mindless.c om> wrote in message[/color]
                      news:<ALJ3d.217 59$Lf5.2677@new ssvr27.news.pro digy.com>...[color=blue][color=green][color=darkred]
                      > > > your thinking is still too influenced by the rigid ASP structure.
                      > > > Relax, open your mind and RTFM on sessions. :-)[/color]
                      > >
                      > > 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[/color][/color]
                      using[color=blue][color=green]
                      > > common files for variable storage/retrieval, or using a database. Some[/color][/color]
                      info[color=blue][color=green]
                      > > should be easily locatable by searching.[/color][/color]


                      Comment

                      • aa

                        #12
                        Re: Application Scope variables ?

                        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.ne t> wrote in message news:414eb86a$0 $80627$ed2619ec @ptn-nntp-reader01.plus.n et...
                        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?

                        Comment

                        • Virgil Green

                          #13
                          Re: Application Scope variables ?


                          "aa" <aa@virgin.ne t> wrote in message
                          news:41505762$0 $42260$ed2e19e4 @ptn-nntp-reader04.plus.n et...[color=blue]
                          > "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[/color]
                          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


                          Comment

                          • Tony Marston

                            #14
                            Re: Application Scope variables ?


                            "aa" <aa@virgin.ne t> wrote in message
                            news:415055cf$0 $42237$ed2e19e4 @ptn-nntp-reader04.plus.n et...[color=blue]
                            > 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[/color]

                            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

                            This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL



                            [color=blue]
                            > "Tony Marston" <tony@NOSPAM.de mon.co.uk> wrote in message
                            > news:cip0pa$ig4 $1$8300dec7@new s.demon.co.uk.. .[color=green]
                            >>
                            >> "aa" <aa@virgin.ne t> wrote in message
                            >> news:415002f7$0 $42212$ed2e19e4 @ptn-nntp-reader04.plus.n et...[color=darkred]
                            >> > 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[/color][/color]
                            > retrieve[color=green][color=darkred]
                            >> > it
                            >> > from disc (a file or DB) and then to write it back?[/color]
                            >>
                            >> 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[/color]
                            > back[color=green]
                            >> everything you put in it.
                            >>
                            >> Note that you do not have to write the session data out to file manually[/color]
                            > as[color=green]
                            >> 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
                            >>
                            >>
                            >>[color=darkred]
                            >> > "Zurab Davitiani" <agt@mindless.c om> wrote in message
                            >> > news:ALJ3d.2175 9$Lf5.2677@news svr27.news.prod igy.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[/color][/color]
                            > using[color=green][color=darkred]
                            >> >> common files for variable storage/retrieval, or using a database. Some
                            >> > info
                            >> >> should be easily locatable by searching.
                            >> >
                            >> >[/color]
                            >>
                            >>[/color]
                            >
                            >[/color]


                            Comment

                            • Tony Marston

                              #15
                              Re: Application Scope variables ?


                              "Virgil Green" <vjg@DESPAMobsy dian.com> wrote in message
                              news:ifV3d.162$ q67.47@newssvr1 1.news.prodigy. com...[color=blue]
                              > "Lucas" <thelucas@direc tbox.com> wrote in message
                              > news:fdb66b30.0 409201432.a2501 59@posting.goog le.com...[color=green]
                              >> Dear Virgil,
                              >>
                              >> your thinking is still too influenced by the rigid ASP structure.
                              >> Relax, open your mind and RTFM on sessions. :-)[/color]
                              >
                              > 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.[/color]

                              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

                              This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL



                              [color=blue]
                              > 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
                              >
                              >[/color]


                              Comment

                              Working...