![]() |
Retaining Variables In Memory?
I tried searching this on google, but all I got was unrelated trash like how to upgrade your computer's RAM and such.
Is there a way to store a variable within one session of a page, and recall it at a later time? Keeping data inside the RAM? Without storing the value in a data file? I don't think this is possible, or else I think I would have stumbled across it already. But it would be so perfect if it were. I will slap PHP across the face if it can't. :( |
There are SESSION and COOKIE variables if that is what you mean. I don't seem to exactly understand what your question is. Here are some links that might help.
http://www.w3schools.com/php/php_cookies.asp http://www.w3schools.com/php/php_sessions.asp |
No, I mean like load an array of 100 random integers in to the RAM in page: "init.php", and then display them straight from the RAM on: "index.php". So then anyone seeing "index.php" would see the exact same thing... as long as "init.php" has been accessed at least once. Then every time "init.php" is accessed, it would cause a different result to show in "index.php".
Note: This is not actually what I'm doing. Just a demonstration of what it could be used for. |
Not on your ordinary, modern, multiple-processed, controlled-by-an-OS-that-ain't you, memory-managed system, no.
|
Your best bet would probably be to write data to a temporary file, and load that in the subsequent page.
|
Oh wow... so I think this really means that Python can sometimes be faster than PHP. Both in efficiency and production. If we were to do this in Python, it would be...
:
...And due to PHP not being able to do the same... there will be a dramatic loss in potential speed. The relevant data is going to be needlessly... loaded, parsed, modified, outputted, formatted, then saved... every time a page is accessed. That makes me sad. :( *slaps PHP* :( |
I'm not a python guy but I doubt even Python stores it in RAM. If I understand this correctly you want to be able to load/generate data by visiting init.php but then have the same data be displayed to everyone on index.php.
You have to store it somewhere on the disk of the server. Either a database, flat-file, or something of the sort. Another possibility is to generate the entire html on the spot. When you visit init.php it will then generate a static html file called index.html that gets updated through init.php. The server will cache some popular pages in RAM although there is no way to force something to stay in RAM. |
No, Python definitely stores it in the RAM. The way Python works, is it is its own server. The HTTP server is embedded within your Python script. So the entire site, everything that can be seen and downloaded, is contained within (at least) one file. You're basically extending the server's capabilities to decide what pages are linked to what.
You don't need Apache to run it (although you can), all you need is one Python script and the necessary files that are used to embed the server (CherryPy). It most certainly is held inside the RAM, or else around 6000 pages on my website would not be working right now. Since PHP can not do this, it's limiting a lot of potential speed ups in efficiency. PHP could get nowhere near the speed of Python+CherryPy in some situations. |
Sounds like you're talking about an ability of CherryPy, not Python, per se. This is a question of a parent process treating all services as children and arranging for shared memory, I would guess.
|
Well, yes. I chose to ignore that fact. I would have hoped PHP had some way to communicate back to Apache to manage memory (PHP --> Apache --> PHP).
Not necessarily in the same manner Python does it (CherryPy --> Python --> CherryPy). |
| All times are GMT -5. The time now is 12:18 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC