ob_start, timeouts with output_callback function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christian Luszick

    ob_start, timeouts with output_callback function

    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_replacevar s($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("Sele ct * FROM $mysql[settings] WHERE
    variable LIKE '\%%'");
    while ($row = mysql_fetch_arr ay($result))
    {
    $rvar = urldecode($row[variable]); // %var%
    $rval = urldecode($row[value]); // realvalue
    $tmp = str_replace($rv ar, $rval, $tmp);
    }
    }
    @mysql_close();
    return $tmp; // output urldecoded
    }




    ob_start("html_ replacevars")

    [..]
    output
    [..]

    ob_end_flush();

  • Christian Luszick

    #2
    Re: ob_start, timeouts with output_callback function


    okay ... I tried the following:


    // ---------------------------------------------
    // replace all internal vars (%..%) in string
    // ---------------------------------------------
    function html_replacevar s($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("Sele ct * FROM $mysql[settings] WHERE
    variable LIKE '\%%'");
    while ($row = mysql_fetch_arr ay($result))
    {
    $rvar = urldecode($row[variable]);
    $rval = urldecode($row[value]);
    $tmp = str_replace($rv ar, $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:
    [color=blue]
    > 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_replacevar s($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("Sele ct * FROM $mysql[settings] WHERE variable
    > LIKE '\%%'");
    > while ($row = mysql_fetch_arr ay($result))
    > {
    > $rvar = urldecode($row[variable]); // %var%
    > $rval = urldecode($row[value]); // realvalue
    > $tmp = str_replace($rv ar, $rval, $tmp);
    > }
    > }
    > @mysql_close();
    > return $tmp; // output urldecoded
    > }
    >
    >
    >
    >
    > ob_start("html_ replacevars")
    >
    > [..]
    > output
    > [..]
    >
    > ob_end_flush();
    >[/color]

    Comment

    Working...