include_once() within a function
include_once() within a function
am 08.09.2007 19:33:44 von Mikhail Kovalev
Hi all,
I have a file which is to be included in another script and which
takes several seconds to load(!), and which is actually not always
used by the script, so instead of using include or include_once in the
beginning, i'm using include_once() within a function, which is called
on demand...
The problem is the new data has the scope of the function, and when
the same function is called again, the data is lost....
What can I possibly do here...
Thanks in advance
Re: include_once() within a function
am 08.09.2007 20:49:55 von luiheidsgoeroe
On Sat, 08 Sep 2007 19:33:44 +0200, Mikhail Kovalev =
wrote:
> Hi all,
> I have a file which is to be included in another script and which
> takes several seconds to load(!), and which is actually not always
> used by the script, so instead of using include or include_once in the=
> beginning, i'm using include_once() within a function, which is called=
> on demand...
> The problem is the new data has the scope of the function, and when
> the same function is called again, the data is lost....
Well, you could assign it to static variable(s) in your function.
function foo(){
static $cache;
if(!$cache){
$cache =3D include('/path/to/file'); //let the include file return the=
=
variables
}
return $cache;
}
-- =
Rik Wasmus
Re: include_once() within a function
am 08.09.2007 21:12:23 von Mikhail Kovalev
On 8 Sep, 20:49, "Rik Wasmus" wrote:
> On Sat, 08 Sep 2007 19:33:44 +0200, Mikhail Kovalev
>
> wrote:
> > Hi all,
> > I have a file which is to be included in another script and which
> > takes several seconds to load(!), and which is actually not always
> > used by the script, so instead of using include or include_once in the
> > beginning, i'm using include_once() within a function, which is called
> > on demand...
> > The problem is the new data has the scope of the function, and when
> > the same function is called again, the data is lost....
>
> Well, you could assign it to static variable(s) in your function.
>
> function foo(){
> static $cache;
> if(!$cache){
> $cache = include('/path/to/file'); //let the include file return the
> variables
> }
> return $cache;
>
> }
>
> --
> Rik Wasmus
return $cache?
My function returns something else...
Mmm, doesn't seem to work even with the return part.
The functions from the included file are preserved, but the variables
which are declared in that file are lost. Ive tried declaring them
static directly inside the included file, but with no luck.....
Btw, the function in question here is called from another function...
Re: include_once() within a function
am 08.09.2007 21:26:47 von Mikhail Kovalev
On 8 Sep, 21:12, Mikhail Kovalev wrote:
> On 8 Sep, 20:49, "Rik Wasmus" wrote:
>
>
>
> > On Sat, 08 Sep 2007 19:33:44 +0200, Mikhail Kovalev
>
> > wrote:
> > > Hi all,
> > > I have a file which is to be included in another script and which
> > > takes several seconds to load(!), and which is actually not always
> > > used by the script, so instead of using include or include_once in the
> > > beginning, i'm using include_once() within a function, which is called
> > > on demand...
> > > The problem is the new data has the scope of the function, and when
> > > the same function is called again, the data is lost....
>
> > Well, you could assign it to static variable(s) in your function.
>
> > function foo(){
> > static $cache;
> > if(!$cache){
> > $cache = include('/path/to/file'); //let the include file return the
> > variables
> > }
> > return $cache;
>
> > }
>
> > --
> > Rik Wasmus
>
> return $cache?
> My function returns something else...
> Mmm, doesn't seem to work even with the return part.
>
> The functions from the included file are preserved, but the variables
> which are declared in that file are lost. Ive tried declaring them
> static directly inside the included file, but with no luck.....
>
> Btw, the function in question here is called from another function...
I guess what I'm looking for is how to make "once-included" variables
global from inside the function....
Re: include_once() within a function
am 08.09.2007 21:37:10 von Mikhail Kovalev
On 8 Sep, 21:26, Mikhail Kovalev wrote:
> On 8 Sep, 21:12, Mikhail Kovalev wrote:
>
>
>
> > On 8 Sep, 20:49, "Rik Wasmus" wrote:
>
> > > On Sat, 08 Sep 2007 19:33:44 +0200, Mikhail Kovalev
>
> > > wrote:
> > > > Hi all,
> > > > I have a file which is to be included in another script and which
> > > > takes several seconds to load(!), and which is actually not always
> > > > used by the script, so instead of using include or include_once in the
> > > > beginning, i'm using include_once() within a function, which is called
> > > > on demand...
> > > > The problem is the new data has the scope of the function, and when
> > > > the same function is called again, the data is lost....
>
> > > Well, you could assign it to static variable(s) in your function.
>
> > > function foo(){
> > > static $cache;
> > > if(!$cache){
> > > $cache = include('/path/to/file'); //let the include file return the
> > > variables
> > > }
> > > return $cache;
>
> > > }
>
> > > --
> > > Rik Wasmus
>
> > return $cache?
> > My function returns something else...
> > Mmm, doesn't seem to work even with the return part.
>
> > The functions from the included file are preserved, but the variables
> > which are declared in that file are lost. Ive tried declaring them
> > static directly inside the included file, but with no luck.....
>
> > Btw, the function in question here is called from another function...
>
> I guess what I'm looking for is how to make "once-included" variables
> global from inside the function....
Allright, Ive solved it by putting them directly into $GLOBALS from
whithin the included file's code...but i dont feel its good
programming. WOuld be very grateful if you have other solutions=))
Re: include_once() within a function
am 08.09.2007 22:05:02 von Jerry Stuckle
Mikhail Kovalev wrote:
> On 8 Sep, 21:12, Mikhail Kovalev wrote:
>> On 8 Sep, 20:49, "Rik Wasmus" wrote:
>>
>>
>>
>>> On Sat, 08 Sep 2007 19:33:44 +0200, Mikhail Kovalev
>>> wrote:
>>>> Hi all,
>>>> I have a file which is to be included in another script and which
>>>> takes several seconds to load(!), and which is actually not always
>>>> used by the script, so instead of using include or include_once in the
>>>> beginning, i'm using include_once() within a function, which is called
>>>> on demand...
>>>> The problem is the new data has the scope of the function, and when
>>>> the same function is called again, the data is lost....
>>> Well, you could assign it to static variable(s) in your function.
>>> function foo(){
>>> static $cache;
>>> if(!$cache){
>>> $cache = include('/path/to/file'); //let the include file return the
>>> variables
>>> }
>>> return $cache;
>>> }
>>> --
>>> Rik Wasmus
>> return $cache?
>> My function returns something else...
>> Mmm, doesn't seem to work even with the return part.
>>
>> The functions from the included file are preserved, but the variables
>> which are declared in that file are lost. Ive tried declaring them
>> static directly inside the included file, but with no luck.....
>>
>> Btw, the function in question here is called from another function...
>
> I guess what I'm looking for is how to make "once-included" variables
> global from inside the function....
>
That's exactly what Rik was telling you.
Whether you include a file or not is immaterial. A static variable
within a function will keep its value between invocation; a non-static
variable will not.
But the real question is - why does it take several seconds to load?
I've never had a PHP file take that long!
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: include_once() within a function
am 08.09.2007 22:08:55 von luiheidsgoeroe
On Sat, 08 Sep 2007 21:12:23 +0200, Mikhail Kovalev =
wrote:
> On 8 Sep, 20:49, "Rik Wasmus" wrote:
>> On Sat, 08 Sep 2007 19:33:44 +0200, Mikhail Kovalev
>>
>> wrote:
>> > Hi all,
>> > I have a file which is to be included in another script and which
>> > takes several seconds to load(!), and which is actually not always
>> > used by the script, so instead of using include or include_once in =
the
>> > beginning, i'm using include_once() within a function, which is cal=
led
>> > on demand...
>> > The problem is the new data has the scope of the function, and when=
>> > the same function is called again, the data is lost....
>>
>> Well, you could assign it to static variable(s) in your function.
>>
>> function foo(){
>> static $cache;
>> if(!$cache){
>> $cache =3D include('/path/to/file'); //let the includ=
e =
>> file return the
>> variables
>> }
>> return $cache;
>>
>> }
>>
> return $cache?
> My function returns something else...
And what is it your function does too? Wouldn't it be better to create a=
=
function just serving the results of the include (which should NOT be =
argument dependant, or caching would be quite another problem), and doin=
g =
something with that variables in another?
> Mmm, doesn't seem to work even with the return part.
>
> The functions from the included file are preserved, but the variables
> which are declared in that file are lost. Ive tried declaring them
> static directly inside the included file, but with no luck.....
Just declaring them static with no check wether they are allready set =
would not have the desired effect.
> Btw, the function in question here is called from another function...
OK, an illustration.
//the function
function get_cached_include(){
static $data =3D array();
if(empty($data)) $data =3D include('/path/to/file');
return $data;
}
?>
//the included file
$bar =3D true;//boolean
$baz =3D array(1,5,6,7);//array
$foz =3D fopen('/path/to/another/file');
return compact('bar','baz','boz');
?>
//the real use
function some_functionality($args){
echo $args['bar'] ? 'bar is true':'bar is false';
foreach($args['baz'] as $baz){
echo "baz value =3D $baz\n";
}
echo is_resource($args['foz']) ? 'foz is a resource':'foz is not a =
resource';
}
//and let's do it:
some_functionality(get_cached_include());
?>
If this doesn't work like you want it to, you'll have to be more specifi=
c =
about your wishes and current best try. See this page about a more =
detailed explanation of static: =
On a side note: a limited argument dependant cache in a function could b=
e =
created thus:
function cache_include_returns(){
static $cache =3D array();
$args =3D func_get_args();
$key =3D serialize($args); //which would mean $args _can_ be serialized=
, =
and aren't to 'big' to be usefull
if(!isset($cache[$key])) $cache[$key] =3D include('/path/to/file');//or=
=
possibly make the file dependant on the arguments...
return $cache[$key];
}
include file:
echo 'You just included '.__FILE__; //should only happen once per unique=
=
arguments
$return =3D "arguments were:";
foreach($args as $k =3D> $v){
$return .=3D "\n\t{$k} =3D> ".strval($v);
}
return $return;
?>
-- =
Rik Wasmus
Re: include_once() within a function
am 08.09.2007 22:12:51 von luiheidsgoeroe
On Sat, 08 Sep 2007 22:05:02 +0200, Jerry Stuckle =
wrote:
> Mikhail Kovalev wrote:
>> On 8 Sep, 21:12, Mikhail Kovalev wrote:
>>> On 8 Sep, 20:49, "Rik Wasmus" wrote:
>>>
>>>
>>>
>>>> On Sat, 08 Sep 2007 19:33:44 +0200, Mikhail Kovalev =
>>>> wrote:
>>>>> Hi all,
>>>>> I have a file which is to be included in another script and which
>>>>> takes several seconds to load(!), and which is actually not always=
>>>>> used by the script, so instead of using include or include_once in=
=
>>>>> the
>>>>> beginning, i'm using include_once() within a function, which is =
>>>>> called
>>>>> on demand...
>>>>> The problem is the new data has the scope of the function, and whe=
n
>>>>> the same function is called again, the data is lost....
>>>> Well, you could assign it to static variable(s) in your function.
>>>> function foo(){
>>>> static $cache;
>>>> if(!$cache){
>>>> $cache =3D include('/path/to/file'); //let the incl=
ude =
>>>> file return the variables
>>>> }
>>>> return $cache;
>>>> }
>>> return $cache?
>>> My function returns something else...
>>> Mmm, doesn't seem to work even with the return part.
>>>
>>> The functions from the included file are preserved, but the variable=
s
>>> which are declared in that file are lost. Ive tried declaring them
>>> static directly inside the included file, but with no luck.....
>>>
>>> Btw, the function in question here is called from another function..=
..
>> I guess what I'm looking for is how to make "once-included" variable=
s
>> global from inside the function....
>>
>
> That's exactly what Rik was telling you.
>
> Whether you include a file or not is immaterial. A static variable =
> within a function will keep its value between invocation; a non-static=
=
> variable will not.
>
> But the real question is - why does it take several seconds to load? =
> I've never had a PHP file take that long!
Well, I have, but normally that would only be so when waiting for outsid=
e =
(3rd party) resources to come trough, or scripts never ment for HTTP use=
=
but for cronjobs. Good point, there may be a lot to optimize there.
-- =
Rik Wasmus
Re: include_once() within a function
am 08.09.2007 22:29:40 von Mikhail Kovalev
On 8 Sep, 22:05, Jerry Stuckle wrote:
> Mikhail Kovalev wrote:
> > On 8 Sep, 21:12, Mikhail Kovalev wrote:
> >> On 8 Sep, 20:49, "Rik Wasmus" wrote:
>
> >>> On Sat, 08 Sep 2007 19:33:44 +0200, Mikhail Kovalev
> >>> wrote:
> >>>> Hi all,
> >>>> I have a file which is to be included in another script and which
> >>>> takes several seconds to load(!), and which is actually not always
> >>>> used by the script, so instead of using include or include_once in the
> >>>> beginning, i'm using include_once() within a function, which is called
> >>>> on demand...
> >>>> The problem is the new data has the scope of the function, and when
> >>>> the same function is called again, the data is lost....
> >>> Well, you could assign it to static variable(s) in your function.
> >>> function foo(){
> >>> static $cache;
> >>> if(!$cache){
> >>> $cache = include('/path/to/file'); //let the include file return the
> >>> variables
> >>> }
> >>> return $cache;
> >>> }
> >>> --
> >>> Rik Wasmus
> >> return $cache?
> >> My function returns something else...
> >> Mmm, doesn't seem to work even with the return part.
>
> >> The functions from the included file are preserved, but the variables
> >> which are declared in that file are lost. Ive tried declaring them
> >> static directly inside the included file, but with no luck.....
>
> >> Btw, the function in question here is called from another function...
>
> > I guess what I'm looking for is how to make "once-included" variables
> > global from inside the function....
>
> That's exactly what Rik was telling you.
>
> Whether you include a file or not is immaterial. A static variable
> within a function will keep its value between invocation; a non-static
> variable will not.
>
> But the real question is - why does it take several seconds to load?
> I've never had a PHP file take that long!
It loads a 1,8 MB array stored as serialized in a file....=)
This is not something i do for web
Re: include_once() within a function
am 08.09.2007 22:33:01 von Michael Fesser
..oO(Mikhail Kovalev)
>On 8 Sep, 22:05, Jerry Stuckle wrote:
>>
>> But the real question is - why does it take several seconds to load?
>> I've never had a PHP file take that long!
>
>It loads a 1,8 MB array stored as serialized in a file....=)
Just curious - what's in that array? Wouldn't it be possible to use a
database instead?
Micha
Re: include_once() within a function
am 08.09.2007 22:42:45 von Jerry Stuckle
Mikhail Kovalev wrote:
> On 8 Sep, 22:05, Jerry Stuckle wrote:
>> Mikhail Kovalev wrote:
>>> On 8 Sep, 21:12, Mikhail Kovalev wrote:
>>>> On 8 Sep, 20:49, "Rik Wasmus" wrote:
>>>>> On Sat, 08 Sep 2007 19:33:44 +0200, Mikhail Kovalev
>>>>> wrote:
>>>>>> Hi all,
>>>>>> I have a file which is to be included in another script and which
>>>>>> takes several seconds to load(!), and which is actually not always
>>>>>> used by the script, so instead of using include or include_once in the
>>>>>> beginning, i'm using include_once() within a function, which is called
>>>>>> on demand...
>>>>>> The problem is the new data has the scope of the function, and when
>>>>>> the same function is called again, the data is lost....
>>>>> Well, you could assign it to static variable(s) in your function.
>>>>> function foo(){
>>>>> static $cache;
>>>>> if(!$cache){
>>>>> $cache = include('/path/to/file'); //let the include file return the
>>>>> variables
>>>>> }
>>>>> return $cache;
>>>>> }
>>>>> --
>>>>> Rik Wasmus
>>>> return $cache?
>>>> My function returns something else...
>>>> Mmm, doesn't seem to work even with the return part.
>>>> The functions from the included file are preserved, but the variables
>>>> which are declared in that file are lost. Ive tried declaring them
>>>> static directly inside the included file, but with no luck.....
>>>> Btw, the function in question here is called from another function...
>>> I guess what I'm looking for is how to make "once-included" variables
>>> global from inside the function....
>> That's exactly what Rik was telling you.
>>
>> Whether you include a file or not is immaterial. A static variable
>> within a function will keep its value between invocation; a non-static
>> variable will not.
>>
>> But the real question is - why does it take several seconds to load?
>> I've never had a PHP file take that long!
>
>
> It loads a 1,8 MB array stored as serialized in a file....=)
>
> This is not something i do for web
>
Definitely not the best implementation. In fact, probably the worse
implementation!
For one thing, the data should not be in the same file as the functions.
And if you need the data, you should read it in.
And Micha is correct - you should be using a database instead.
Don't screw up your code even more due to a lousy implementation.
Rather, fix the implementation.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: include_once() within a function
am 08.09.2007 22:53:06 von Mikhail Kovalev
On 8 Sep, 22:33, Michael Fesser wrote:
> .oO(Mikhail Kovalev)
>
> >On 8 Sep, 22:05, Jerry Stuckle wrote:
>
> >> But the real question is - why does it take several seconds to load?
> >> I've never had a PHP file take that long!
>
> >It loads a 1,8 MB array stored as serialized in a file....=)
>
> Just curious - what's in that array? Wouldn't it be possible to use a
> database instead?
>
> Micha
It's a tree of 20 levels. Like arrays in an array in etc
I have no experience with Mysql which would be the only option in my
case, sort of new to php as well, and im unsure of amount of work
needed to rewrite the code,
Load time is only some 10-15 seconds anyway, but very heavy on RAM on
my machine, illl tell you hehe
Re: include_once() within a function
am 08.09.2007 22:57:53 von Mikhail Kovalev
On 8 Sep, 22:42, Jerry Stuckle wrote:
> Mikhail Kovalev wrote:
> > On 8 Sep, 22:05, Jerry Stuckle wrote:
> >> Mikhail Kovalev wrote:
> >>> On 8 Sep, 21:12, Mikhail Kovalev wrote:
> >>>> On 8 Sep, 20:49, "Rik Wasmus" wrote:
> >>>>> On Sat, 08 Sep 2007 19:33:44 +0200, Mikhail Kovalev
> >>>>> wrote:
> >>>>>> Hi all,
> >>>>>> I have a file which is to be included in another script and which
> >>>>>> takes several seconds to load(!), and which is actually not always
> >>>>>> used by the script, so instead of using include or include_once in the
> >>>>>> beginning, i'm using include_once() within a function, which is called
> >>>>>> on demand...
> >>>>>> The problem is the new data has the scope of the function, and when
> >>>>>> the same function is called again, the data is lost....
> >>>>> Well, you could assign it to static variable(s) in your function.
> >>>>> function foo(){
> >>>>> static $cache;
> >>>>> if(!$cache){
> >>>>> $cache = include('/path/to/file'); //let the include file return the
> >>>>> variables
> >>>>> }
> >>>>> return $cache;
> >>>>> }
> >>>>> --
> >>>>> Rik Wasmus
> >>>> return $cache?
> >>>> My function returns something else...
> >>>> Mmm, doesn't seem to work even with the return part.
> >>>> The functions from the included file are preserved, but the variables
> >>>> which are declared in that file are lost. Ive tried declaring them
> >>>> static directly inside the included file, but with no luck.....
> >>>> Btw, the function in question here is called from another function...
> >>> I guess what I'm looking for is how to make "once-included" variables
> >>> global from inside the function....
> >> That's exactly what Rik was telling you.
>
> >> Whether you include a file or not is immaterial. A static variable
> >> within a function will keep its value between invocation; a non-static
> >> variable will not.
>
> >> But the real question is - why does it take several seconds to load?
> >> I've never had a PHP file take that long!
>
> > It loads a 1,8 MB array stored as serialized in a file....=)
>
> > This is not something i do for web
>
> Definitely not the best implementation. In fact, probably the worse
> implementation!
>
> For one thing, the data should not be in the same file as the functions.
> And if you need the data, you should read it in.
>
Theyre not, the file to be included is a collection of 10 functions. A
separate data file is loaded in a variable by a line of code from this
script, ie when this file is run (or included in this case)
Re: include_once() within a function
am 08.09.2007 23:15:11 von Jerry Stuckle
Mikhail Kovalev wrote:
> On 8 Sep, 22:33, Michael Fesser wrote:
>> .oO(Mikhail Kovalev)
>>
>>> On 8 Sep, 22:05, Jerry Stuckle wrote:
>>>> But the real question is - why does it take several seconds to load?
>>>> I've never had a PHP file take that long!
>>> It loads a 1,8 MB array stored as serialized in a file....=)
>> Just curious - what's in that array? Wouldn't it be possible to use a
>> database instead?
>>
>> Micha
>
> It's a tree of 20 levels. Like arrays in an array in etc
>
> I have no experience with Mysql which would be the only option in my
> case, sort of new to php as well, and im unsure of amount of work
> needed to rewrite the code,
> Load time is only some 10-15 seconds anyway, but very heavy on RAM on
> my machine, illl tell you hehe
>
A relational database would speed things up considerably. Especially if
you don't need all of the items.
And 10-15 seconds? Very few users are going to wait that long, and only
the most desperate will do it repeatedly.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: include_once() within a function
am 08.09.2007 23:18:53 von Mikhail Kovalev
On 8 Sep, 22:08, "Rik Wasmus" wrote:
> On Sat, 08 Sep 2007 21:12:23 +0200, Mikhail Kovalev
>
>
>
> wrote:
> > On 8 Sep, 20:49, "Rik Wasmus" wrote:
> >> On Sat, 08 Sep 2007 19:33:44 +0200, Mikhail Kovalev
>
> >> wrote:
> >> > Hi all,
> >> > I have a file which is to be included in another script and which
> >> > takes several seconds to load(!), and which is actually not always
> >> > used by the script, so instead of using include or include_once in the
> >> > beginning, i'm using include_once() within a function, which is called
> >> > on demand...
> >> > The problem is the new data has the scope of the function, and when
> >> > the same function is called again, the data is lost....
>
> >> Well, you could assign it to static variable(s) in your function.
>
> >> function foo(){
> >> static $cache;
> >> if(!$cache){
> >> $cache = include('/path/to/file'); //let the include
> >> file return the
> >> variables
> >> }
> >> return $cache;
>
> >> }
>
> > return $cache?
> > My function returns something else...
>
> And what is it your function does too? Wouldn't it be better to create a
> function just serving the results of the include (which should NOT be
> argument dependant, or caching would be quite another problem), and doing
> something with that variables in another?
>
> > Mmm, doesn't seem to work even with the return part.
>
> > The functions from the included file are preserved, but the variables
> > which are declared in that file are lost. Ive tried declaring them
> > static directly inside the included file, but with no luck.....
>
> Just declaring them static with no check wether they are allready set
> would not have the desired effect.
>
> > Btw, the function in question here is called from another function...
>
> OK, an illustration.
>
>
> //the function
> function get_cached_include(){
> static $data = array();
> if(empty($data)) $data = include('/path/to/file');
> return $data;}
>
> ?>
>
>
> //the included file
> $bar = true;//boolean
> $baz = array(1,5,6,7);//array
> $foz = fopen('/path/to/another/file');
> return compact('bar','baz','boz');
> ?>
>
>
> //the real use
> function some_functionality($args){
> echo $args['bar'] ? 'bar is true':'bar is false';
> foreach($args['baz'] as $baz){
> echo "baz value = $baz\n";
> }
> echo is_resource($args['foz']) ? 'foz is a resource':'foz is not a
> resource';}
>
> //and let's do it:
> some_functionality(get_cached_include());
> ?>
>
> If this doesn't work like you want it to, you'll have to be more specific
> about your wishes and current best try. See this page about a more
> detailed explanation of static:
>
>
> On a side note: a limited argument dependant cache in a function could be
> created thus:
>
> function cache_include_returns(){
> static $cache = array();
> $args = func_get_args();
> $key = serialize($args); //which would mean $args _can_ be serialized,
> and aren't to 'big' to be usefull
> if(!isset($cache[$key])) $cache[$key] = include('/path/to/file');//or
> possibly make the file dependant on the arguments...
> return $cache[$key];
>
> }
>
> include file:
>
> echo 'You just included '.__FILE__; //should only happen once per unique
> arguments
> $return = "arguments were:";
> foreach($args as $k => $v){
> $return .= "\n\t{$k} => ".strval($v);}
>
> return $return;
> ?>
>
> --
> Rik Wasmus
I think I grasped the main portion of your example, but the approach
is completely infamiliar to me.
Heres my situation:
main file:
function1($arg1) {
include_once('included_file.php');
return function_from_included_file_3($arg1, var1, var2, var3); //
var1,2,3 see below
}
function2($arg1) {
if then else etc
return function1($arg1);
}
?>
included file:
function_from_included_file_1...
function_from_included_file_2...
function_from_included_file_3...
var1
var2
var3...
?>
my problem is that i fail to make var1, var2, var3 static, when the
second time function1 from main file is called
Re: include_once() within a function
am 08.09.2007 23:21:10 von Mikhail Kovalev
On 8 Sep, 23:15, Jerry Stuckle wrote:
> Mikhail Kovalev wrote:
> > On 8 Sep, 22:33, Michael Fesser wrote:
> >> .oO(Mikhail Kovalev)
>
> >>> On 8 Sep, 22:05, Jerry Stuckle wrote:
> >>>> But the real question is - why does it take several seconds to load?
> >>>> I've never had a PHP file take that long!
> >>> It loads a 1,8 MB array stored as serialized in a file....=)
> >> Just curious - what's in that array? Wouldn't it be possible to use a
> >> database instead?
>
> >> Micha
>
> > It's a tree of 20 levels. Like arrays in an array in etc
>
> > I have no experience with Mysql which would be the only option in my
> > case, sort of new to php as well, and im unsure of amount of work
> > needed to rewrite the code,
> > Load time is only some 10-15 seconds anyway, but very heavy on RAM on
> > my machine, illl tell you hehe
>
> A relational database would speed things up considerably. Especially if
> you don't need all of the items.
>
> And 10-15 seconds? Very few users are going to wait that long, and only
> the most desperate will do it repeatedly.
i can imagine =)
well good news is it's not a web application, just for personal use,
using php to analize some statistics