Hey all.
Sorry to waste your time on the below thread. Multiple recursion killing PHP was not the problem after all. Recursively calling an sql query with the same param was the problem -- doh! Machines & humans don't do too well with processing infinite loops....
Error: "Premature end of script headers: php.exe" (not syntax error -- internal server error)
I've seen a few posts on this error, but my situation is, I believe, a little different.
I'm running win2k, apache 2.0.53, php 4.3.1 on my local webserver.
PHP pages load flawlessly except for when I run my site tree generator; i.e. page to display navigable site tree for popup menu "challenged" users.
This class utilizes two recursive functions: get_branch(), which retrieves the site tree; i.e. recursively runs through db stored site tree; for each leaf found print_leaf() link & title to screen. if leaf has children, call get_branch() recursively. See function below:
function get_branch($id) {
/* get children */
$sql = "SELECT tree_id as id
FROM site_tree_new
WHERE parent_id = $id
ORDER BY title";
$r = new db_query($sql);
if($r->num_rows()) {
while($q = mysql_fetch_array($r->result)) {
/* get leaf */
$this->print_leaf($q['id']);
if($this->has_children($q['id'])) {
$this->get_branch($q['id']);
}
/* reset params for next loop iteration */
$this->reset_params();
}
}
}
The other recursive function is get_level() -- used to determine the branch level of a given leaf. See function below:
function get_level($id) {
/* determine level */
$sql = "SELECT tree_id as id, parent_id
FROM table
WHERE tree_id = $id";
$r = new db_query($sql);
while($q = mysql_fetch_array($r->result)) {
/* call get_level() recursively until root item found */
if($q['parent_id'] != 0) {
$this->level++;
$this->get_level($q['id']);
}
elseif($this->is_root != 1) {
$this->level++;
}
}
}
If I omit any calls to get_level(), the page loads just fine, although I need to determine the branch level of a given leaf to properly format the site tree.
The only thing I can think of, and this may be horribly ignorant ;--), is that PHP dies when it is asked to process concurrent recursive functions -- i.e. for each leaf, the above recursive get_level() function is called; and, when a leaf has children, a recursive function is called to retrieve child item data. See get_branch() function below:
Maybe I'm asking too much from PHP? I don't know.
Anyone who's got a clue as to what's causing this, let me know...
Thanks,
--Noah