cache problem
am 13.04.2008 09:12:16 von yhd1997
Can you please help me to solve this cache problem?
I have a php script that can save the content to a cache folder. But I
can not get it to work to display the cached page.
The script will generate dynamic content by calling: index.php?
operation=1¶meter=2&id=3
It will save the content to cache as operation=1¶meter=2&id=3
At the beginning of the index.php, it will check if the cached file
exist. if it does exist and time is less than cached configuration
time then include the cached file and exit. otherwise save the content
as cached file using the server query string as its name.
However the code to display cache file doesn't work. Here is the code
snipe:
// Get from the cache
if(file_exists($cache_file) && time() - $cache_time <
filemtime($cache_file)) {
include($cache_file);
exit;
}
Is there anything wrong with above code to retrieve the file with a
name like operation=1¶meter=2&id=3?
Re: cache problem
am 13.04.2008 15:38:41 von Jerry Stuckle
yhd1997@gmail.com wrote:
> Can you please help me to solve this cache problem?
>
> I have a php script that can save the content to a cache folder. But I
> can not get it to work to display the cached page.
>
> The script will generate dynamic content by calling: index.php?
> operation=1¶meter=2&id=3
>
> It will save the content to cache as operation=1¶meter=2&id=3
>
> At the beginning of the index.php, it will check if the cached file
> exist. if it does exist and time is less than cached configuration
> time then include the cached file and exit. otherwise save the content
> as cached file using the server query string as its name.
>
> However the code to display cache file doesn't work. Here is the code
> snipe:
>
> // Get from the cache
> if(file_exists($cache_file) && time() - $cache_time <
> filemtime($cache_file)) {
> include($cache_file);
> exit;
> }
>
> Is there anything wrong with above code to retrieve the file with a
> name like operation=1¶meter=2&id=3?
>
There doesn't look to be a problem with the code you showed us. But not
having all the code, it's impossible to tell what might be wrong.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: cache problem
am 13.04.2008 17:07:32 von yhd1997
Here is the script:
$cache_dir =3D './cached/';
$cache_file =3D '';
$cache_param =3D $_SERVER["QUERY_STRING"];
$cache_time =3D 3660;
$cache_file =3D $cache_dir.$cache_file.$cache_param;
// Get from the cache
if(file_exists($cache_file) && time() - $cache_time <
filemtime($cache_file)) {
include($cache_file);
exit;
}
else {
chdir("script");
include("common.php");
}
ob_start();
//code to generate content start
.. ...
//code to generate content end
$outputbuf =3D ob_get_contents();
ob_end_clean();
include("header.php");
echo $outputbuf;
include("footer.php");
chdir("../");
$fp =3D fopen($cache_file,'w+');
fwrite($fp, $outputbuf);
fclose($fp);
ob_end_flush();
?>
> There doesn't look to be a problem with the code you showed us. =A0But not=
> having all the code, it's impossible to tell what might be wrong.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Hide quoted text -=
>
> - Show quoted text -
Re: cache problem
am 13.04.2008 18:30:26 von yhd1997
OK. It's working now. I guess it's just a path issue.
On Apr 13, 11:07=A0am, yhd1...@gmail.com wrote:
> Here is the script:
>
>
> $cache_dir =3D './cached/';
> $cache_file =3D '';
> $cache_param =3D $_SERVER["QUERY_STRING"];
>
> $cache_time =3D 3660;
>
> $cache_file =3D $cache_dir.$cache_file.$cache_param;
>
> // Get from the cache
> if(file_exists($cache_file) && time() - $cache_time <
> filemtime($cache_file)) {
> =A0 include($cache_file);
> =A0 exit;}
>
> else {
> =A0 chdir("script");
> =A0 =A0 =A0 =A0 include("common.php");
>
> }
>
> =A0 =A0 =A0 =A0 ob_start();
>
> //code to generate content start
> ... ...
> //code to generate content end
>
> =A0 =A0 =A0 =A0 $outputbuf =3D ob_get_contents();
>
> =A0 =A0 =A0 =A0 ob_end_clean();
>
> =A0 =A0 =A0 =A0 include("header.php");
> =A0 =A0 =A0 =A0 echo $outputbuf;
> =A0 =A0 =A0 =A0 include("footer.php");
>
> =A0 =A0 =A0 =A0 =A0 chdir("../");
>
> $fp =3D fopen($cache_file,'w+');
> fwrite($fp, $outputbuf);
> fclose($fp);
> ob_end_flush();
> ?>
>
>
>
> > There doesn't look to be a problem with the code you showed us. =A0But n=
ot
> > having all the code, it's impossible to tell what might be wrong.
>
> > --
> > ==================
> > Remove the "x" from my email address
> > Jerry Stuckle
> > JDS Computer Training Corp.
> > jstuck...@attglobal.net
> > ==================- Hide quoted text=
-
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
Re: cache problem
am 13.04.2008 21:37:55 von Norman Peelman
yhd1997@gmail.com wrote:
> OK. It's working now. I guess it's just a path issue.
>
> On Apr 13, 11:07 am, yhd1...@gmail.com wrote:
>> Here is the script:
>>
>>
>> $cache_dir = './cached/';
>> $cache_file = '';
>> $cache_param = $_SERVER["QUERY_STRING"];
>>
>> $cache_time = 3660;
>>
>> $cache_file = $cache_dir.$cache_file.$cache_param;
>>
>> // Get from the cache
>> if(file_exists($cache_file) && time() - $cache_time <
>> filemtime($cache_file)) {
>> include($cache_file);
>> exit;}
>>
>> else {
>> chdir("script");
>> include("common.php");
>>
>> }
>>
>> ob_start();
>>
>> //code to generate content start
>> ... ...
>> //code to generate content end
>>
>> $outputbuf = ob_get_contents();
>>
>> ob_end_clean();
>>
>> include("header.php");
>> echo $outputbuf;
>> include("footer.php");
>>
>> chdir("../");
>>
>> $fp = fopen($cache_file,'w+');
>> fwrite($fp, $outputbuf);
>> fclose($fp);
>> ob_end_flush();
>> ?>
>>
>>
>>
>>> There doesn't look to be a problem with the code you showed us. But not
>>> having all the code, it's impossible to tell what might be wrong.
>>> --
>>> ==================
>>> Remove the "x" from my email address
>>> Jerry Stuckle
>>> JDS Computer Training Corp.
>>> jstuck...@attglobal.net
>>> ==================- Hide quoted text -
>>> - Show quoted text -- Hide quoted text -
>> - Show quoted text -
>
Why not install APC or memcache?
--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
Re: cache problem
am 13.04.2008 22:05:51 von colin.mckinnon
On 13 Apr, 14:38, Jerry Stuckle wrote:
> yhd1...@gmail.com wrote:
>
> > However the code to display cache file doesn't work. Here is the code
> > snipe:
What do you mean it doesn't work? It doesn't think the cache file
exists? Is current? Fails to read it? Is there an error message? Have
you checked the file was written and is readable by the webserver uid?
Have you checked the contents of the cached file?
>
> > // Get from the cache
> > if(file_exists($cache_file) && time() - $cache_time <
> > filemtime($cache_file)) {
> > include($cache_file);
> > exit;
> > }
>
> > Is there anything wrong with above code to retrieve the file with a
> > name like operation=1¶meter=2&id=3?
>
> There doesn't look to be a problem with the code you showed us. But not
> having all the code, it's impossible to tell what might be wrong.
>
Error messages (or verification that there are none) would be good
too.
C.