473,757 Members | 10,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

when does a PHP script stop running?

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.
Jul 17 '05 #1
7 7825
>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?


I have yet to find any good reason why anyone would not use error logging
to a file, regardless of the other methods they choose to implement for
error logging.

On a production website, you would normally have display_errors set off, and
your
error logging to a file should be what you use to figure out what if any
problems are
occuring.

_______________ _______________ _______________ ____
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Jul 17 '05 #2
<la*******@hotm ail.com> wrote in message
I have yet to find any good reason why anyone would not use error logging
to a file, regardless of the other methods they choose to implement for
error logging.

On a production website, you would normally have display_errors set off, and
your
error logging to a file should be what you use to figure out what if any
problems are
occuring.


Good point. My project isn't yet in production and has drifted from
server to server in a discouraging way. In particular, its kept me
from setting things up correctly on the server. But things are more
stable now, so I should go ahead and set things up properly.

Still, having said that, the question remains: when does a PHP script
stop running.
Jul 17 '05 #3
lawrence wrote:
$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";
}
}

Are you sure, *really* sure, that "registerSessio ns" went into
$actionsToBeDon e[0]? And "sendHtmlToBrow sers" went into
$actionsToBeDon e[1]? And "incrementPageV iews" went into
$actionsToBeDon e[2]?

If there is a 'hole' in the array the for() loop will fail miserably. Do
a foreach loop instead:

foreach ($actionsToBeDo ne as $function) {
if ($allowed = isFunctionAllow ed($function)) {
// ... etc ...
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #4
Pedro Graca <he****@hotpop. com> wrote in message news:<c2******* ******@ID-203069.news.uni-berlin.de>...
lawrence wrote:
$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";
}
}

Are you sure, *really* sure, that "registerSessio ns" went into
$actionsToBeDon e[0]? And "sendHtmlToBrow sers" went into
$actionsToBeDon e[1]? And "incrementPageV iews" went into
$actionsToBeDon e[2]?

If there is a 'hole' in the array the for() loop will fail miserably. Do
a foreach loop instead:

foreach ($actionsToBeDo ne as $function) {
if ($allowed = isFunctionAllow ed($function)) {
// ... etc ...

Nice! That is the kind of double-check on my thinking that I
appreciate. I will go test that. These newsgroups are at their most
useful when people catch me on my assumptions like that.
Jul 17 '05 #5
Pedro Graca <he****@hotpop. com> wrote in message
Are you sure, *really* sure, that "registerSessio ns" went into
$actionsToBeDon e[0]? And "sendHtmlToBrow sers" went into
$actionsToBeDon e[1]? And "incrementPageV iews" went into
$actionsToBeDon e[2]?

If there is a 'hole' in the array the for() loop will fail miserably. Do
a foreach loop instead:

foreach ($actionsToBeDo ne as $function) {
if ($allowed = isFunctionAllow ed($function)) {
// ... etc ...

Sadly, it still doesn't work. I redid the loops so that they now use
list() and each() and the array has a string index. Then I did a
simple test. As I mentioned before, any functions put into the first
two loops seem to run fine, but it is as if PHP stops running once all
the HTML is sent. Here is the class method that handles the 3 loops:


/**
* 12-31-03 - manipulator
*
* All the events that happen while this software is running must be
triggered by some event
* loaded into one of these arrays. This software goes through the
arrays and runs the allowed
* functions.
*
* public
* returns void
*/
function runMainLoop() {
// 05-13-03 - the architexture of this software is simple, put your
functions in one of these 3 arrays:
//
// $pageEventStart - this is for functions that must execute before
any HTML is sent to the browser - stuff dealing with cookies, for
instance.
//
// $pageEventMiddl e - this is for functions that should appear on
screen. Often, I assume, this would be in conjunction with
renderPageCance l=true. XML sitemaps, for instance. renderPage(), too,
most obviously.
//
// $pageEventEnd - this is for functions that should execute after
all the HTML is sent to the visitor. updateNumTimesA rticleViewed()
would be an example.

// 11-15-03 - I put this next line here just to keep things a little
cleaner - lk
$allowed = $GLOBALS["arrayOfAllAllo wedFunctions"];

// 09-17-03 - this function is getting moved to $pageRender today -
lk
if (is_array($this->pageEventStart )) {
ksort($this->pageEventStart );
while (list($key, $val) = each($this->pageEventStart )) {
$function = $val;
$function2 = $allowed[$function];
if ($function2) {
if (function_exist s($function2)) {
$function2();
} else {
$this->controllerForA ll->import($functi on);
if (function_exist s($function2)) {
$function2();
} else {
$this->resultsObjec t->addToErrorResu lts("In runMainLoop(), in
the class McPageRender, in the loop for the array pageEventStart, we
tried to import the function called '$function', but controllerForAl l
could not find it.");
}
}
} else {
$this->resultsObjec t->addToErrorResu lts("In runMainLoop(), in the
class McPageRender, in the loop for the array pageEventStart, we
sought a function called '$function' in the official array of allowed
functions, but nothing came back. Please check spelling and check the
array.");
}
}
}
if (is_array($this->pageEventMiddl e)) {
ksort($this->pageEventMiddl e);
while (list($key, $val) = each($this->pageEventMiddl e)) {
$function = $val;
$function2 = $allowed[$function];
if ($function2) {
if (function_exist s($function2)) {
$function2();
} else {
$this->controllerForA ll->import($functi on);
if (function_exist s($function2)) {
$function2();
} else {
$this->resultsObjec t->addToErrorResu lts("In runMainLoop(), in
the class McPageRender, in the loop for the array pageEventMiddle , we
tried to import the function called '$function', but controllerForAl l
could not find it.");
}
}
} else {
$this->resultsObjec t->addToErrorResu lts("In runMainLoop(), in the
class McPageRender, in the loop for the array pageEventMiddle , we
sought a function called '$function' in the official array of allowed
functions, but nothing came back. Please check spelling and check the
array.");
}
}
}
if (is_array($this->pageEventEnd )) {
ksort($this->pageEventEnd );
while (list($key, $val) = each($this->pageEventEnd )) {
$function = $val;
$function2 = $allowed[$function];
if ($function2) {
if (function_exist s($function2)) {
$function2();
} else {
$this->controllerForA ll->import($functi on);
if (function_exist s($function2)) {
$function2();
} else {
$this->resultsObjec t->addToErrorResu lts("In runMainLoop(), in
the class McPageRender, in the loop for the array pageEventEnd, we
tried to import the function called '$function', but controllerForAl l
could not find it.");
}
}
} else {
$this->resultsObjec t->addToErrorResu lts("In runMainLoop(), in the
class McPageRender, in the loop for the array pageEventEnd, we sought
a function called '$function' in the official array of allowed
functions, but nothing came back. Please check spelling and check the
array.");
}
}
}
}



As a simle test, I put this file in the folder where all events are
stored:

<?php

// 10-04-03 - I hope this turns out to be a good idea. These global
events, rather than have them hardcoded in a lot of
// scattered files, I'm going to try to group them in a folder called
GlobalEvents. All of these events will be automatically
// included. The events assigned to the global arrays are actually
function names that should be called by runMainLoop() or
// renderMainConte nt.
global $pageEventEnd;
$pageEventEnd["testEndEve nt"] = "testEndEve nt";

?>

Then I wrote this function, but I got nothing:
function testEndEvent() {

echo "<h1>hello</h1>";

}


Any ideas?
Jul 17 '05 #6
lawrence wrote:
it still doesn't work. (snip) Any ideas?


Simplify your script to a bare minimum, identify the error there (or
post that bare minimum here), keep adding bits of code and reverifying
until you get the error again

<?php
class Manipulator {
var $pageEventStart ;
var $pageEventMiddl e;
var $pageEventEnd;

function runMainLoop() {
ProcessArray($t his->pageEventStart );
ProcessArray($t his->pageEventMiddl e);
ProcessArray($t his->pageEventEnd );
}
}

/* this function should be a method of Manipulator -- but I am not used
* to OOP and it's pitfalls */
function ProcessArray($a rr) {
if (!is_array($arr )) return;
ksort($arr);
while (list($key, $val) = each($arr)) {
$val($key);
}
}

function fx($x) {
echo "fx('$x') worked.\n";
}

$x = new Manipulator();

$x->pageEventSta rt['ES1'] = 'fx';
$x->pageEventSta rt['ES2'] = 'fx';
$x->pageEventMiddl e['EM1'] = 'fx';
$x->pageEventMiddl e['EM2'] = 'fx';
$x->pageEventEnd['EE1'] = 'fx';
$x->pageEventEnd['EE2'] = 'fx';

$x->runMainLoop( );
?>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #7
Pedro Graca <he****@hotpop. com> wrote in message news:<c3******* ******@ID-203069.news.uni-berlin.de>...
lawrence wrote:
it still doesn't work.

(snip)
Any ideas?


Simplify your script to a bare minimum, identify the error there (or
post that bare minimum here), keep adding bits of code and reverifying
until you get the error again


Thank you, I'll try it. The experimental method can teach much. I was
asking here to see if this was a bug or expected behavior. You seem
confident this is a bug, so I will try your experiment.
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2886
by: Damien Renwick | last post by:
I have a php script which simply stops midway through a while loop that processes records returned by a MySQL query. The HTML page continues trying to load the page but the php has stopped running and eventually I get a timeout. The script is running in my development environment which consists of php 4.3.4, Apache 1.3.28 and MySQL 4.0.17, installed on Windows XP with Service Pack 2. I suspect that there may be a problem with my...
2
7083
by: TonyJeffs | last post by:
I'm new to this, and stole/doctored my code from the "Ugly JavaScript Handbook" I have a slide show program. First theres stuff to set up the array, and the time between slides Then a function startIt()is defined then a function stopIt() Then two buttons, Start and Stop, which when pressed call the relevant functions
5
27344
by: Paul O. Morris | last post by:
Is there a script that I can run to stop a particular SQL server service on Win2003 server? I'm looking for a similar script to restart that service as well. Thanks.
4
9222
by: Vlad Hrybok | last post by:
I am using Application_End to send out a notification about application being unloaded. I found that those notifications are not being sent because the app seems to get unloaded without Application_End ever being called. We started logging Application_Start and Application_End events and found that the number is not even: Application_Start happen more often than Application_End. My question is: What are the sutuations in which we should...
9
4912
by: Rea | last post by:
Hi eb I set some 'Stop' statements and also visual breakpoints in asp code (vbscript). I am doing that in Microsoft Script debugger. Than I refresh the original page and expect execution to halt at these breakpoints but unfortunatly it does not.. I had allowed script debugging in both iis home directory and in internet explorer. Also i added everyone from active directory to be members of debugging group. Web Server is W2k sp4 and iis...
2
1738
by: ANarula | last post by:
I am running into a strange problem. I have perl script which reads the "APPDATA" environment variable, and does some work on that directory. When I a launch this script from Command Prompt, it works perfectly fine, however when the same script is launched from a DLL hosted in a particular Service, the script fails to read the envrionment variable. Does any one has any clue, whats going wrong ? Regards,
6
5253
by: John (Z R) L | last post by:
Hi all, I am very new to programming, and I chose to study the Python language before C++. I am currently using the Wikibooks "Non-Programmer's Tutorial for Python", and am up to the section "Who goes there"? http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python/Who_Goes_There%3F But after clicking "run module" for " a = 1
39
2469
by: Alan Isaac | last post by:
This may seem very strange, but it is true. If I delete a .pyc file, my program executes with a different state! In a single directory I have module1 and module2. module1 imports random and MyClass from module2. module2 does not import random. module1 sets a seed like this::
3
3696
by: WP | last post by:
Hello, I have a very simple script (or would you call it a batch file?) with the following content: connect to mydb2; DROP TABLE staff_employee_address; DROP TABLE staff_employee_address_telephone; DROP TABLE staff_employee; DROP TABLE staff; commit; terminate;
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.