By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

ob_start, timeouts with output_callback function

P: n/a
hi,

I am using output buffering with ob_start and a callback function, which
replaces variables like "%var%" with the equivilants taken out of a
mysql database. This works well! But I get sometimes php timeouts (max
execution time (30s) exceeded ...). The Server should be really fast
enough (dual PIII, >1 GB RAM) and runs with PHP 4.1.2 and MySQL 3.23.56.

Any suggestions? Known Probs?!

I am still trying to find a solution by my self ( and an error in my
script) ... but hopefully someone can give me a hint ...
cu :: cal

full code:

// ---------------------------------------------
// replace all internal vars (%..%) in string
// ---------------------------------------------
function html_replacevars($tmp) // input urldecoded
{
global $mysql;
db_connect();
// replace all %*% in value
for ($i=0;$i<2;$i++) // twice because of recursive use of %*%
{
$result = db_result("Select * FROM $mysql[settings] WHERE
variable LIKE '\%%'");
while ($row = mysql_fetch_array($result))
{
$rvar = urldecode($row[variable]); // %var%
$rval = urldecode($row[value]); // realvalue
$tmp = str_replace($rvar, $rval, $tmp);
}
}
@mysql_close();
return $tmp; // output urldecoded
}


ob_start("html_replacevars")

[..]
output
[..]

ob_end_flush();

Jul 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

okay ... I tried the following:
// ---------------------------------------------
// replace all internal vars (%..%) in string
// ---------------------------------------------
function html_replacevars($input) // input urldecoded
{
global $mysql;
db_connect();
$tmp = $input; // this prevents timeouts ...
strange, but works!
// replace all %*% in value
for ($i=0;$i<2;$i++)
{
$result = db_result("Select * FROM $mysql[settings] WHERE
variable LIKE '\%%'");
while ($row = mysql_fetch_array($result))
{
$rvar = urldecode($row[variable]);
$rval = urldecode($row[value]);
$tmp = str_replace($rvar, $rval, $tmp);
}
}
@mysql_close();
return $tmp; // output urldecoded
}
by using a replacement variable $input to $tmp it works fast and stable.
I've read this hint in a user comment in the php manual.

Christian Luszick wrote:
hi,

I am using output buffering with ob_start and a callback function, which
replaces variables like "%var%" with the equivilants taken out of a
mysql database. This works well! But I get sometimes php timeouts (max
execution time (30s) exceeded ...). The Server should be really fast
enough (dual PIII, >1 GB RAM) and runs with PHP 4.1.2 and MySQL 3.23.56.

Any suggestions? Known Probs?!

I am still trying to find a solution by my self ( and an error in my
script) ... but hopefully someone can give me a hint ...
cu :: cal

full code:

// ---------------------------------------------
// replace all internal vars (%..%) in string
// ---------------------------------------------
function html_replacevars($tmp) // input urldecoded
{
global $mysql;
db_connect();
// replace all %*% in value
for ($i=0;$i<2;$i++) // twice because of recursive use of %*%
{
$result = db_result("Select * FROM $mysql[settings] WHERE variable
LIKE '\%%'");
while ($row = mysql_fetch_array($result))
{
$rvar = urldecode($row[variable]); // %var%
$rval = urldecode($row[value]); // realvalue
$tmp = str_replace($rvar, $rval, $tmp);
}
}
@mysql_close();
return $tmp; // output urldecoded
}


ob_start("html_replacevars")

[..]
output
[..]

ob_end_flush();


Jul 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.