Chris
Chris

Reputation: 59491

Issue with cache?

I'm trying to install a webviewer for Teamspeak 3 (a VoIP program) but I do have some issues. First of all, the official website has discontinued support as of 1 month ago, so I cannot ask them unfortunately.

When I go to the webviewer page the first time everything seems to work just fine. However if I refresh the page it goes white and loads until I get:

PHP Fatal error:  Maximum execution time of 30 seconds exceeded in C:\Users\[...]\TSQuery.class.php on line 414

Here is line 414 from that file:

    $ret .= fgets($this->connection, 8096);

and the whole function:

private function send_raw($text)
{
    $i = -1;
    $ret = '';
    if ($this->connection === NULL)
    {
        $this->open_new_connection();
    }
    stream_set_timeout($this->connection, 0, 300000);
    fputs($this->connection, $text);

    do
    {
        $ret .= fgets($this->connection, 8096);
    }
    while (strstr($ret, "error id=") === false);

    return $ret;
}

I have tried this both on my webhost and moving the script over to the same server as the VoIP is installed on (thinking the host might be causing something) - but to no difference.

When I put the script as an iframe on my webhost and reload the page twice the whole site goes down!

Service Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
Apache Server at www.site.com Port 80

But back to my own server, every now and again (1 / 10 loads or so) I get:

PHP Notice:  Undefined property: TSQuery::$cachepath in C:\Users\[...]\TSQuery.class.php on line 85

and here is line 85:

$this->cachepath .= $port . "/";

and the whole function:

public function use_by_port($port)
{
    if (is_numeric($port))
    {

        $resp = $this->send_cmd("use port=" . $port);
        if ($resp['error']['id'] === 0)
        {
            $this->cachepath .= $port . "/";
        }
        return $resp;
    }
    return false;
}

any ideas???

Thanks!

Upvotes: 0

Views: 209

Answers (1)

bestprogrammerintheworld
bestprogrammerintheworld

Reputation: 5520

do
{
    $ret .= fgets($this->connection, 8096);
}
while (strstr($ret, "error id=") === false);

The code above means: connect WHILE not first occurence of "error_id=" is found (is false). This means that if no errors occur it will connect in an infinite loop and I believe that's why you're getting a timeout.

UPDATE:

I would skip the do/while and do something like this instead:

if(!$this->connection) return false;

$output = fgets($this->connection, 8096);
fputs($this->connection, $text);
fclose($this->connection);

if (substr($output, 0, 4) == '1 OK') return true;

return false;

Upvotes: 1

Related Questions