Page 1 of 1
var lifespans, page init question
Posted: Mon Apr 28, 2003 12:16 am
by keredson
let's say i have the following:
Code: Select all
<?
$monthї0] = "jan";
$monthї1] = "feb";
...
$monthї11] = "dec";
?>
this is wasteful, as the PHP engine is going to be creating a static array each time the page is requested. how do i tell the engine to execute this code only ONCE, when the page is initially loaded? and then make the array available for each request of this page made?
thanks,
-- derek
Posted: Mon Apr 28, 2003 1:50 am
by []InTeR[]
What i know is,
that php compiles when you hit the page.
So each code is compiled again, and again, and again.
I know that
zend has a 'pre'-compile something.
Posted: Mon Apr 28, 2003 2:12 am
by twigletmac
You can use sessions to store information between requests...
http://www.php.net/manual/en/ref.session.php
Mac
Posted: Mon Apr 28, 2003 9:11 am
by keredson
yep, i considered that, but that only marginally decreases the performance problem. you see, it would still be evaled for each new visitor.
the information is static both across requests for the page AND across visitors for the page. in fact, the contents of the array should never change at all, and it should only ever have to be be created once.
i'm a JSP developer usually - i'm looking for the equiv of the init method, which is run once (and only once) when a JSP or a servlet is first loaded/intrepreted.
Posted: Mon Apr 28, 2003 9:26 am
by volka
there is no such method in a php script. Basically the script is executed from the beginning when invoked. There is no persistence between requests (save the cache and a few exceptions).
Code: Select all
<?php
$month = array('jan', 'feb', ..., 'dec');
?>
might speed your example up a bit.