473,547 Members | 2,642 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Whats PHPs version of ASPs application scope variable

In ASP you can create a variable that is accessible by all scripts in
an application.

Is this possible in PHP? Storing a multi-dimensional array in memory
has much greater performance benefits than storing in a database or
session (which just gets saved to disk anyway). Id like to have my
commonly used application variables in memory.

Is this possible or is it one of the few flaws of PHP?

-Nick
Jul 17 '05 #1
7 16052

On 29-Dec-2003, nb********@hotm ail.com (Nick) wrote:
In ASP you can create a variable that is accessible by all scripts in
an application.

Is this possible in PHP? Storing a multi-dimensional array in memory
has much greater performance benefits than storing in a database or
session (which just gets saved to disk anyway). Id like to have my
commonly used application variables in memory.

Is this possible or is it one of the few flaws of PHP?


http://www.php.net/manual/en/languag...bles.scope.php

scroll down to the global keyword
--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@wil lglen.net (it's reserved for spammers)
Jul 17 '05 #2
Nick wrote:
Is this possible in PHP? Storing a multi-dimensional array in memory
has much greater performance benefits than storing in a database or
session (which just gets saved to disk anyway). Id like to have my
commonly used application variables in memory.

Is this possible or is it one of the few flaws of PHP?


There are a few ways to do this. One way is to use the 'global' keyword
in your functions. Another is to use the $GLOBALS array, but the one I
like most is to create a custom ini file and use parse_ini_file to read
the data. This makes for the easiest editing - especially by users.

Then if you set the auto_prepend_fi le setting via a .htaccess file, this
would be similar to using a globals.asp file (I think that's what it was
called anyway).

/includes/globals.php.ini
--------------------------
<?php exit; // in case it's called by a browser ?>
[section1]
var1 = val1
var2 = val2

[section2]
var1 = val2.1
var2 = val2.2

/includes/globals.php
---------------------
<?php
$CFG=parse_ini_ file(dirname(__ FILE__).'/globals.ini.php ',TRUE);
?>

/test.php
---------
<?php
echo'<pre>';
print_r($CFG);
echo'</pre>';
?>

/.htaccess
----------
php_value auto_prepend_fi le "/home/user/www/includes/globals.php"

The above would then output this:
Array
(
[section1] => Array
(
[var1] => val1
[var2] => val2
)

[section2] => Array
(
[var1] => val2.1
[var2] => val2.2
)

)

If you don't set the second argument to parse_ini_file, then you'd get:
Array
(
[var1] => val2.1
[var2] => val2.2
)
--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #3
Nick <nb********@hot mail.com> wrote:
In ASP you can create a variable that is accessible by all scripts in
an application.

Is this possible in PHP? Storing a multi-dimensional array in memory
has much greater performance benefits than storing in a database or
session (which just gets saved to disk anyway).
You might use shared memory and semphores for this
http://nl3.php.net/manual/en/ref.sem.php
Id like to have my
commonly used application variables in memory.


If it's static data a simple include()/require() is better suited (might
be in the diskcache).

--

Daniel Tryba

Jul 17 '05 #4
PHP has no concept of an "applicatio n", unlike ASP.Net. PHP is a scripting
language, and from the view of PHP, the "applicatio n" is the current file
plus anything include()d or require()d.

Your best shot is probably either just writing out everything to a file like
vars.inc.php which you include on all pages (and re-writing that file as
necessary), or storing the information in some sort of database if that
turns out to be more practical.

Some people may call this a shortfall, others just see it as a design
philosophy. ASP.Net is designed around applications and tasks, PHP is
designed around scripts and procedures. (And no, I don't mean to start some
tech flame war, or anything like that. I'm simply saying that ASP.Net has a
concept of applications in the sense of multiple source files compiled into
a single application, supports OOP fully etc, whereas PHP is extremely well
suited towards procedural programming and scripting, but lacks the
facilities for full OOP and the concept of an "applicatio n" as opposed to
simply a collection of code.)

"Nick" <nb********@hot mail.com> wrote in message
news:ce******** *************** ***@posting.goo gle.com...
In ASP you can create a variable that is accessible by all scripts in
an application.

Is this possible in PHP? Storing a multi-dimensional array in memory
has much greater performance benefits than storing in a database or
session (which just gets saved to disk anyway). Id like to have my
commonly used application variables in memory.

Is this possible or is it one of the few flaws of PHP?

-Nick

Jul 17 '05 #5
Regarding this well-known quote, often attributed to Nick's famous "29 Dec
2003 11:42:50 -0800" speech:
In ASP you can create a variable that is accessible by all scripts in
an application.

Is this possible in PHP? Storing a multi-dimensional array in memory
has much greater performance benefits than storing in a database or
session (which just gets saved to disk anyway). Id like to have my
commonly used application variables in memory.

Is this possible or is it one of the few flaws of PHP?

-Nick


I'm not familiar with the ASP definition of an "Applicatio n". Does it
consist of only one HTML output (as in "a lot of includes, but only one
final output") or does the "Applicatio n" refer to multiple pages which
perform a common function?

If it's the former, AFAIK, any global variables, if you call them with
"global" in any functions, persist into and out of included files. If
you're talking the latter, then sessions are about the best way to go.

--
-- Rudy Fleminger
-- sp@mmers.and.ev il.ones.will.bo w-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
Jul 17 '05 #6
Damn guys you dont know anything about ASP, only Agelmar know what is the Application concept in ASP, in PHP, the only comparaison
whould be Apache predefined variable, but you can't define your own as ASP do. The Application variable is all variables you
created for the whole server, this mean every ASP websites on this server can use these variables. There is not equivalence in PHP.
The only workaround whould be to use an include on all pages.
How sad :(

Savut

"Nick" <nb********@hot mail.com> wrote in message news:ce******** *************** ***@posting.goo gle.com...
In ASP you can create a variable that is accessible by all scripts in
an application.

Is this possible in PHP? Storing a multi-dimensional array in memory
has much greater performance benefits than storing in a database or
session (which just gets saved to disk anyway). Id like to have my
commonly used application variables in memory.

Is this possible or is it one of the few flaws of PHP?

-Nick

Jul 17 '05 #7
Savut wrote:
Damn guys you dont know anything about ASP
hmm... never did claim to know anything about it.
only Agelmar know what is the Application concept in ASP
Then perhaps the OP should have described it a bit more in detail to
give us a clue.
in PHP, the only comparaison
whould be Apache predefined variable, but you can't define your own as ASP do.
Actually, you can - in httpd.conf using similar to:
SetEnv TestString "Test String With Spaces"
SetEnv TestNumber 3157851357

This can go in the global for all hosted sites on the server to access,
or inside VirtualHost directives on a per-domain basis. Also, if you
want a number of domains to use them (but not all), you can place them
in a separate file and use the Include directive inside VirtualHosts to
get the values. You can also use that syntax in .htaccess files as well
to define your variables on a per directory basis.

You then access variables set with this method via the $_SERVER array.
The Application variable is all variables you
created for the whole server, this mean every ASP websites on this
server can use these variables. There is not equivalence in PHP.
The only workaround whould be to use an include on all pages.
How sad :(


Right, isn't that what I illustrated using parse_ini_file and
auto_prepend in my post? ;) Only difference is you don't have to add a
line of code to every file to include it.

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #8

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

Similar topics

33
15843
by: aa | last post by:
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?
2
2612
by: Robert | last post by:
I have an application migrated from 1.1 to 2.0 via VS2005. Under 1.1 I could do the following to return the version information (as found in the assemblyinfo.vb file) GetVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly.Location).FileMajorPart.ToString + "." +...
6
8333
by: shaun | last post by:
If I put (define) const variables at the top of a .cpp file but do not declare them in the .h file, are they only visible within that .cpp file? e.g. const int a={1,2,3,4}; in a cpp file will be a 'global' with file scope? (no flames for oxymoron, please), available for use inside my functions which are defined in the same file (but...
5
1983
by: Rich | last post by:
The following code produced a singleton object with application scope when it should have had page scope: public class Singleton { private static Singleton uniqueInstance = null; private Singleton() { } public static Singleton getInstance()
1
2995
by: spolsky | last post by:
i use an application scope recordset object for holding the list of online users. i am not sure that if i have to handle concurrency issues like one user is looping through the recordset for getting the list of online users while another one is getting online so adding a new record. ado recordset has a free and apartment threading...
0
1262
by: José Joye | last post by:
Hello, I'm trying to use the VS2005 Settings file so as to get strongly typed settings. I want the following: - Have all my application setting (with application scope) defined centrally in my app.exe.config file - give the right to assemblies to have their own settings file (e.g.: for settings used only internally)
0
1710
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); $data = shmop_read($shm_id, 0, $shm_size); $_APP=$_APP = unserialize($data); }
0
1476
by: Umbrae | last post by:
Hey guys, Just wanted to ask your opinion - I just wrote up and released as Open Source a class called AppCache. AppCache is an easy to use class implementation of an Application scope in PHP, using Memcached as the backend. If any of you have any criticisms or concerns, (or hey, even a few compliments), I'd appreciate it much. :)
5
6119
by: chromis | last post by:
Hi there, I've recently been updating a site to use locking on application level variables, and I am trying to use a commonly used method which copies the application struct into the request scope. Application variables are then accessed in this manner Request.App.<Var>. To begin with I had a simple functioning login system inside a...
0
7510
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7463
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7797
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6032
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5362
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3493
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3473
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1923
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 we have to send another system

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.