Suppose I create dynamic web pages with 3 functions (which call other
functions to make everything happen, but these 3 you might think of as
being the top layer):
registerSession s();
sendHtmlToBrows ers();
incrementPageVi ews();
Is there any chance that incrementPageVi ews() will be executed? Or, to
turn that question around, does anyone know a reason why it wouldn't?
Does PHP stop executing when the last of the HTML is sent to the
webbrowser (I've heard both yes and no on this newsgroup and I'm
hoping for a definitive answer).
Okay, now lets suppose that I do this (this is closer to what I
actually do):
$actionsToBeDon e[] = "registerSessio ns";
$actionsToBeDon e[] = "sendHtmlToBrow sers";
$actionsToBeDon e[] = "incrementPageV iews";
for ($i=0; $i < count($actionsT oBeDone); $i++) {
$function = $actionsToBeDon e[$i];
if ($allowed = isFunctionAllow ed($function)) {
$function();
} else {
echo "<h1> Someone tried to commit a function called $function
which is not allowed";
}
}
Given this situation, is there a reason why incrementPageVi ews would
never execute?
What I actually do is have 3 such arrays, $pageEventsStar t,
$pageEventsMidd le, and $pageEventsEnd, and I have a single function
that has 3 for loops, like the one you see above. I am not able to get
any functions to fire if I put them into $pageEventsEnd, yet the same
functions work fine if I put them into $pageEventsStar t.
There are some calls to the database that should be done after all the
HTML is sent. Otherwise they just slow things down. Incrementing how
many times a page has been viewed, or deleting all sessions that are
more than 20 minutes old, are the kind of clean up work that I'd like
to put into $pageEventStart . But it seems like PHP is quitting before
it gets to $pageEventsStar t. I find this shocking because it means
that PHP is quitting in the middle of a function, without even
finishing the function (because, as I say, all three for loops are in
one function).
The other possibility is that an error happens but that I don't see
the error message because it is generated after all HTML is sent to
the browser. Can anyone think of how I might find this error message,
if it existed?
Just so you get it, the master function that runs my software looks
like this:
function runMainLoop() {
$pageEventsStar t = $GLOBALS["pageEventsStar t"];
$pageEventsMidd le = $GLOBALS["pageEventsMidd le"];
$pageEventsEnd = $GLOBALS["pageEvents End"];
for ($i=0; $i < count($pageEven tsStart); $i++) {
$function = $pageEventsStar t[$i];
if ($allowed = isFunctionAllow ed($function)) {
$function();
} else {
echo "<h1> Someone tried to commit a function called $function
which is not allowed";
}
}
for ($i=0; $i < count($pageEven tsMiddle); $i++) {
$function = $pageEventsMidd le[$i];
if ($allowed = isFunctionAllow ed($function)) {
$function();
} else {
echo "<h1> Someone tried to commit a function called $function
which is not allowed";
}
}
for ($i=0; $i < count($pageEven tsEnd); $i++) {
$function = $pageEventsEnd[$i];
if ($allowed = isFunctionAllow ed($function)) {
$function();
} else {
echo "<h1> Someone tried to commit a function called $function
which is not allowed";
}
}
}
Does anyone see a reason why runMainLoop() would die before finishing?
If there is an error, it is not in the functions that I'm trying to
execute, because, as I say, when I move them from $pageEventsEnd to
$pageEventsStar t, they work perfectly.