Azu Posted February 6, 2007 Share Posted February 6, 2007 How can I make a permanent global variable that will never be unset unless I specifically set it to null? (Permanent meaning it will still exist after a page finishes executing) Quote Link to comment https://forums.phpfreaks.com/topic/37281-permanent-global-variable/ Share on other sites More sharing options...
hvle Posted February 6, 2007 Share Posted February 6, 2007 As far as I know, everything on a php scripts would be wipe off the system memory upon finishing of execution. So, it not possible, even Static variables. Maybe someone else have different idea? Quote Link to comment https://forums.phpfreaks.com/topic/37281-permanent-global-variable/#findComment-178124 Share on other sites More sharing options...
phat_hip_prog Posted February 6, 2007 Share Posted February 6, 2007 Write the variable to a file (like a config file or /proc/), then when required, read the file. You could try setting a global variable using eval and getting the same way! Quote Link to comment https://forums.phpfreaks.com/topic/37281-permanent-global-variable/#findComment-178134 Share on other sites More sharing options...
Azu Posted February 6, 2007 Author Share Posted February 6, 2007 I would like to avoid having to read and write to files, if possible, since it is much faster to have it already loaded to begin with, then to constantly read and write large amounts of data to files =\ What do you mean about the global variable with eval? Can you please go into a bit more detail? Quote Link to comment https://forums.phpfreaks.com/topic/37281-permanent-global-variable/#findComment-178137 Share on other sites More sharing options...
Azu Posted February 9, 2007 Author Share Posted February 9, 2007 Bump >_> Quote Link to comment https://forums.phpfreaks.com/topic/37281-permanent-global-variable/#findComment-180585 Share on other sites More sharing options...
kenrbnsn Posted February 9, 2007 Share Posted February 9, 2007 You can use session variables. Sessions are usually stick around as long as the browser window is open. Ken Quote Link to comment https://forums.phpfreaks.com/topic/37281-permanent-global-variable/#findComment-180589 Share on other sites More sharing options...
Azu Posted February 13, 2007 Author Share Posted February 13, 2007 I need something that will be permanent, meaning if the person formats their hardrive the variable will still be on the server. I need to use a lot of them, with large amounts of data in them, so I can't just write them to disk and read them off the disk over and over. Quote Link to comment https://forums.phpfreaks.com/topic/37281-permanent-global-variable/#findComment-183718 Share on other sites More sharing options...
Jessica Posted February 13, 2007 Share Posted February 13, 2007 ...That doesn't make any sense Quote Link to comment https://forums.phpfreaks.com/topic/37281-permanent-global-variable/#findComment-183720 Share on other sites More sharing options...
roopurt18 Posted February 13, 2007 Share Posted February 13, 2007 I'm going to set up a little scenario here. Let's say you type something in notepad on your computer at home. Now let's say you want what you typed to be permanent. Now I'm going to ask a stupid question. Do you save the file to disk or do you just walk away from the computer and hope that what you typed will still be there 30 days later? Keep in mind that this computer might be used for many, many other tasks that could potentially warrant a system restart. In addition, environmental conditions could cause it to be turned off for hardware maintenance or repairs. If you want the information to be permanent, you have one choice. Save it to the server's hard disk. You have two choices on how you do that: 1) Creating your own files with fopen, fwrite, fread, etc. 2) Database, MySQL seems to go hand-in-hand with PHP. Quote Link to comment https://forums.phpfreaks.com/topic/37281-permanent-global-variable/#findComment-183810 Share on other sites More sharing options...
Azu Posted February 13, 2007 Author Share Posted February 13, 2007 In that scenario it would probably be better to save it to disk. My scenario is different though. Let's say you have a file that is 900MBs in size, and you only need to restart the server it's on once every few months, and noone else uses it, and you have plenty of ram. Do you save the the whole file to disk every time there is 1 modification and close it only to open it again a few seconds later, and do this over and over every few seconds, or do you just leave it open, and save it to disk once a day and have it load on startup? I'm trying to find a way to accomplish the latter. Quote Link to comment https://forums.phpfreaks.com/topic/37281-permanent-global-variable/#findComment-183824 Share on other sites More sharing options...
roopurt18 Posted February 13, 2007 Share Posted February 13, 2007 Perhaps if you told us something of the file we could guide you better. Quote Link to comment https://forums.phpfreaks.com/topic/37281-permanent-global-variable/#findComment-184064 Share on other sites More sharing options...
trq Posted February 13, 2007 Share Posted February 13, 2007 Global variables should be avoided as much as possible, you seem hell bent on having them.... why? You may have some luck setting up environment variables within Apache itself and then retrieving them through PHP. Seems alot of work for something that in all reality is just going to make your code less secure and a bit messy. Quote Link to comment https://forums.phpfreaks.com/topic/37281-permanent-global-variable/#findComment-184068 Share on other sites More sharing options...
Azu Posted February 14, 2007 Author Share Posted February 14, 2007 I need to have a huge amount of data constantly being modified on a regular bases from many different connections. Reading and writing it to disk simply takes to long I have tried it already, so I need to find a way to keep it in ram. Unless you know of a better way? o_o Quote Link to comment https://forums.phpfreaks.com/topic/37281-permanent-global-variable/#findComment-184133 Share on other sites More sharing options...
hitman6003 Posted February 14, 2007 Share Posted February 14, 2007 Ummm, a database? Oracle keeps as much data as possible in RAM...there is a free version that's limited to 4GB of RAM and I think 4 TB of data...you can assign it enough RAM to keep your data there. Quote Link to comment https://forums.phpfreaks.com/topic/37281-permanent-global-variable/#findComment-184137 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.