Unexpected PHP script caching behaviour ??
| From: | Paulo Parola | Date: | Tue, 02 Jan 2001 21:54:41 +0000 |
| Subject: | Unexpected PHP script caching behaviour ?? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-32372@lists.php.net to get a copy of this message | ||
Hi,
In every file in our project we do an 'include_once()' at the very top of
the file, so that all common constants, global variables and functions are
accessible everywhere.
Recently we started experiencing from time to time unexpected 'cannot
redeclare function xxx' or 'cannot redeclare constant xxx' errors. The
strange thing is that it is not an error that happens every time, but
sporadically and with no apparent standard of when it happens.
We replicated the platform our client has locally, that is,
PHP Version 4.0.3pl1
System Windows NT 4.0 build 1381
Server API ISAPI
ZEND_DEBUG disabled
Thread Safety enabled
and I post here two scripts with which to replicate the error:
TEST1.PHP
==========================
<?php
// Define a constant
define('TEST1_ALREADY_PROCESSED', 'Yes');
// Declare and set a variable
$var1 = "123";
// Define a function
function test($var) {
echo "Variable: $var";
}
?>
TEST2.PHP
==========================
<?php
// I want all errors and warnings reported
error_reporting(E_ALL);
// This should give me no problems since the already defined constants
// and declared functions and variables would NOT be redeclared
// It does not matter if I use 'include', 'include_once',
'require_once', I
always
// endup with PHP trying to redeclare/redefine things.
include_once('test1.php');
// Test if function exists
if (function_exists('test'))
echo "function test defined<br>\n";
else
echo "function test NOT defined<br>\n";
// Test if constant is defined
if (defined('TEST1_ALREADY_PROCESSED'))
echo "constant TEST1_ALREADY_PROCESSED defined<br>\n";
else
echo "constant TEST1_ALREADY_PROCESSED NOT defined<br>\n";
?>
RESULTS
=========================
A) In some ocasions the script runs as expected and ALWAYS output the
following:
function test defined
constant TEST1_ALREADY_PROCESSED defined
B) But then sometimes the NT server (IIS? PHP?) starts 'caching' elements
previously defined in memory so that I got the following results:
The first time the script TEST2.PHP runs fine and outputs:
function test defined
constant TEST1_ALREADY_PROCESSED defined
The second time the script is run (and from then on), I got the following
output:
Warning: Constant test1_already_processed already defined in test1.php on
line 3
Fatal error: Cannot redeclare test() in test1.php on line 7
NOTE: I know that the static HTML pages generated by the script are not
being cached, and that PHP is indeed re-interpreting the files. In order to
proove that I changed the beginning of TEST2.PHP to read as below:
<?php
echo "Just to test<br>";
// I want all errors and warnings reported
error_reporting(E_ALL);
.
.
.
?>
And the output started being the following:
Just to test
Warning: Constant test1_already_processed already defined in test1.php on
line 3
Fatal error: Cannot redeclare test() in test1.php on line 7
--
Please HELP!!!
Paulo
pparola@gst.com.br