mohamedsaeed27 / xmpphp

Automatically exported from code.google.com/p/xmpphp
0 stars 0 forks source link

Add checks if connection is available to methods like disconnect #36

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create an instance of the XMPPHP class
3. Call the disconnect method

Okay this is actually a dumbed down example to reproduce the problem
normaly you would first call the connect method catch the exception and so
on. I have encountered this problem becase i created a facade class for the
xmpp object which calls the disconnect method on deconstruction of the
object which basicly does almost the same like this example:

require_once 'XMPPHP/XMPP.php';

$xmpp = new XMPPHP_XMPP('unavailableserver.de', 80, 'test', 'test', 'none');
$xmpp->disconnect();

What is the expected output?
Nothing should happen :) Atleast the script should not run until it reaches
the php timeout limit.

What do you see instead?
In its current state the script runs until the php timeout limit is reached
because the disconnect method trys to send the stream close stanza.

What version of the product are you using? On what operating system?
Tested with SVN release 54 of XMPPHP on openSUSE 11.0 with PHP
5.2.5 running on Apache 2.2.6.

Please provide any additional information below.
Add checks to affected methods like XMPPHP_XMLStream::disconnect if the
xmpp connection is available, maybe the best solution would be to add the
check only to the XMPPHP_XMLStream::send method.

Original issue reported on code.google.com by ota.ma...@gmail.com on 3 Sep 2008 at 2:31

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Btw i fixed the problem by applying following patch to the disconnect method.

Beeing unsure if this is an approach that appeals to you and if its the correct
approach i only see this as a tmp. fix.

Index: XMLStream.php
===================================================================
--- XMLStream.php   (revision 54)
+++ XMLStream.php   (working copy)
@@ -293,6 +293,9 @@
     * Disconnect from XMPP Host
     */
    public function disconnect() {
+        if (false === (bool) $this->socket) {
+            return;
+        }
        $this->log->log("Disconnecting...",  XMPPHP_Log::LEVEL_VERBOSE);
        $this->reconnect = false;
        $this->send($this->stream_end);

Original comment by ota.ma...@gmail.com on 3 Sep 2008 at 2:42

GoogleCodeExporter commented 8 years ago
Implemented in SVN

Original comment by nathanfr...@gmail.com on 26 Nov 2008 at 10:10