Dear folks,
I've experieced that PHP executing the same script multiple times again.
First time was when foreach() was destorying memory due to invalid data
type is passed to foreach(). (Fixed by Andi. Thanks) Now I have another
code that make script execute multiple times. (PHP 4.0.7RC1, PHP
4.0.8-dev) Wired behaviors are exactly the same as foreach() bug.
I verified multiple script execution by ob_get_contents(), die() and
error_log().
Simplfied(Pesudo) code is as follows (Note: simple code will not
reproduce this problem)
======== BEGIN =========
<?php
ob_start();
class foo {
function foo() {
switch($user_input1) {
case 'A':
$this->handle_user_input1();
break;
case '..':
// Call other user input1 hanlder
break;
}
// print(ob_get_contents()); <= Debug code #1. Uncomment this
displays RESULT_HTML*(RESULT_HTML+ERROR_HTML)*3.
// die(__FILE__.__LINE__); <= Debug code #2. Uncommenting this
displays RESULT_HTML+error_HTML
}
function handle_user_input1() {
switch($user_input2) {
case 'X':
// do some work
if ($multiple_submit) {
include('ERROR_HTML'); // Error page show multiple submit for the
same data.
}
else {
include('RESULT_HTML'); // Result page shows sccuessful submit
// die(__FILE__.__LINE__); <= Debug code #3. Uncommenting this
displys RESULT_HTML.
}
}
}
} // class foo
$obj = new foo;
?>
========== END =========
When I uncomment Debug code #1. Browser displays
RESULT_HTML+(RESULT_HTML*ERROR_HTML)*N. (Note: RESULT_HTML+ERROR_HTML is
displied N times) If I comment out Debug code #1, I get
RESULT_HTML*ERROR_HTML.
When I uncomment Debug code #2, script dies and displays
RESULT_HTML+ERROR_HTML.
When I uncomment Debug code #3, script displays RESULT_HTML.
I see page 'RESULT_HTML' followed by 'ERROR_HTML' which should never
happen. When I put error_log(), there are log messages indicating the
method is called multiple times. It seems Zend engine (output buffering
code or other code) hides multiple script executions somewhat/somehow.
I've already modified the script so that PHP will not execute the same
script multiple times. (I moved code, that detectes multiple submit, to
other script, then PHP stopped doing this) I didn't find out which PHP
function/language construct/feature is causing this problem so far. I
don't get core file. (I'll report this bug if I could get core or find
out what's wrong)
Anyway, Zend engine seems to have tendency executing script multiple
times when there is memory corruption.
error_log()/die() (or gdb) can be used find out this problem, but it's
much easier to find if PHP has trace log feature. I think it would be
useful to find some bugs in PHP itself as well as script bugs created by
users.
Is it feasible to add trace log option that enables logging
function/class method names called? (At least for debug enabled PHP?)
--
Yasuo Ohgaki
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]