hi there,
some long time ago #33 had some suggestions and there was even a discussion #3
lets get it on
in case class is used for a bot in daemon mode (runs infinite in the backbround doing his assigned tasks)
did you know, that this line if(empty($data))
d9f7d46#diff-6d8bfb1cf539d16b81e45de812c980cbR4285
will never get evaluated if the socket dies (server restart, server stop, crash)?
the loop will stuck in a endless fgets, cpu core will go 100%, i metioned this issue allrady here #33
but it got ignored, and surprisingly nothing changed since then.
you cant read any data if there is no resource socket, its a blackhole endless loop.
if you dont belive, try it out, use this and turn the server off after 10 sec, and watch your bots/scripts CPU load and watch your console.
<?PHP
$ts3_ip = '127.0.0.1';
$ts3_queryport = 10011;
$ts3_user = 'serveradmin';
$ts3_pass = 'password';
$ts3_port = 9987;
require("../lib/ts3admin.class.php");
$tsAdmin = new ts3admin($ts3_ip, $ts3_queryport);
if($tsAdmin->getElement('success', $tsAdmin->connect())) {
$tsAdmin->login($ts3_user, $ts3_pass);
$tsAdmin->selectServer($ts3_port);
while(1){
print_r($tsAdmin->version());
sleep(2);
}
}else{
echo 'Connection could not be established.';
}
?>
on server "crash" we should see in the console

but as you see, we see nothing, only our CPU goes crazy.
my solution below:
do {
if(is_resource( $this->runtime['socket'] ) === false || @feof( $this->runtime['socket'] ) === true){
if(is_resource( $this->runtime['socket'] ) === true){
@fclose($this->runtime['socket']);
}
$this->runtime['socket'] = $this->runtime['bot_clid'] = '';
$this->addDebugLog('Socket closed.', $tracert[1]['function'], $tracert[0]['line']);
return $this->generateOutput(false, array('Socket closed.'), false);
}
$data .= @fgets($this->runtime['socket'], 4096);
if(strpos($data, 'error id=3329 msg=connection') !== false) {
$this->runtime['socket'] = $this->runtime['bot_clid'] = '';
$this->addDebugLog('You got banned from server. Socket closed.', $tracert[1]['function'], $tracert[0]['line']);
return $this->generateOutput(false, array('You got banned from server. Connection closed.'), false);
}
} while(strpos($data, 'msg=') === false or strpos($data, 'error id=') === false);
check if the socket is still alive and not at its end of "life" before we use fgets, so you can safely fetch data, and i repeat again if the socket dies we should get this output:

honestly, we get nothing but a blackhole loop, no output, no errors and a 100% cpu load.
so i hope you can eval this issue to see that i dont talk rubbish.
kind regards, stefano
edit: this post's code can be ignored because i came up with new updates, see the posts below.
hi there,
some long time ago #33 had some suggestions and there was even a discussion #3
lets get it on
in case class is used for a bot in daemon mode (runs infinite in the backbround doing his assigned tasks)
did you know, that this line
if(empty($data))d9f7d46#diff-6d8bfb1cf539d16b81e45de812c980cbR4285
will never get evaluated if the socket dies (server restart, server stop, crash)?
the loop will stuck in a endless fgets, cpu core will go 100%, i metioned this issue allrady here #33
but it got ignored, and surprisingly nothing changed since then.
you cant read any data if there is no resource socket, its a blackhole endless loop.
if you dont belive, try it out, use this and turn the server off after 10 sec, and watch your bots/scripts CPU load and watch your console.
on server "crash" we should see in the console

but as you see, we see nothing, only our CPU goes crazy.
my solution below:
check if the socket is still alive and not at its end of "life" before we use fgets, so you can safely fetch data, and i repeat again if the socket dies we should get this output:

honestly, we get nothing but a blackhole loop, no output, no errors and a 100% cpu load.
so i hope you can eval this issue to see that i dont talk rubbish.
kind regards, stefano
edit: this post's code can be ignored because i came up with new updates, see the posts below.