Jump to content

Recommended Posts

not really sure about this one.. i have tried to find the answer.. but couldnt really find out anything... basically.. say I have an app that on first invocation defines a bunch of constants.. will these be redefined upon every request ? .. like from many users.. say there are 100 users logged in..

 

if i have a function say

 

if (!defined('SOME_CONST')) define('SOME_CONST',true);

 

will this be done ONLY on first invocation.. and for each request there after its already defined and exists in memory.. or ..not?

 

Might be a lame question to some.. and i would already guess that its done on first request only but just wanted to verify..

 

J

Link to comment
https://forums.phpfreaks.com/topic/115500-constants-memory-usage-and-creation/
Share on other sites

Constants are like any other variables in that they are only defined for the currently executing script.  They do not persist from page to page and they are unset when the script finishes executing.  User B does not have access to user A's constants.  User A does not have access to the defined constants of a previously requested script. 

 

If you want information to be accessible by several people, you need to store and retrieve the information in a database or flatfile. 

 

If you want information to persist from page to page for 1 user, you can use a database, flatfile, or use a session variable.

ic.. that actually kind of sucks.. as this is not the case for java servlet apps running under tomcat.. these applications are always running.. and they have listeners for http requests.. constants live on .. but wouldnt that make sense.. a constant say gravity is the same for any user .. or should i say site and request wide global constants.. perhaps these are better stored in the host environment?

 

J

right.. well maybe i should tell you the situation..

 

its for a locale based setup which uses defines for labels of fields depending on language ..

 

what I wanted to do was create a single file for each language which contained all definitions for labels in each particular language (the definitions themselves are synced with a database so that when creating each language file we can guarantee each definition has a value)

 

but these files are going to be pretty large.. and to have it read on each request makes no sense.. i thought that if all constants on the site could be preloaded into memory that would be a huge performance benefit.. (of course this means preloaded for each user but only once) ..

 

I guess this isnt possible.. the other option and probably best practice is to define a language file for each page and it loaded when required ..

 

Thanks

 

J

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.