Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: Client destructor - option to keep socket open #63

Closed
bkdotcom opened this issue Jul 1, 2019 · 1 comment
Closed

Comments

@bkdotcom
Copy link

bkdotcom commented Jul 1, 2019

https://github.com/Textalk/websocket-php/blob/master/lib/Client.php#L37

class Client extends Base

class Base {

  public function __destruct() {
    if ($this->socket) {
      if (get_resource_type($this->socket) === 'stream') fclose($this->socket);
      $this->socket = null;
    }
  }

}

PHP Warning: fwrite() expects parameter 1 to be resource, null given in vendor/textalk/websocket/lib/Base.php on line 251

PHP Fatal error: Uncaught exception 'WebSocket\ConnectionException' with message 'Could only write out of 557 bytes.' in vendor/textalk/websocket/lib/Base.php:256

I have encountered an object destructing and attempting to send a message after WebSocket/Client's destructor (It's an Error notification system)..

would be nice to have a 'destruct' : false (default: true) option to not close the socket / don't set to null in __destruct

  public function __destruct() {
    if ($this->options['destruct'] && $this->socket) {
      if (get_resource_type($this->socket) === 'stream') fclose($this->socket);
      $this->socket = null;
    }
  }
@sirn-se
Copy link
Contributor

sirn-se commented Apr 26, 2020

If the Client is destructed, it will not be available for send/receive anyhow. So this really doesn't make any sense. Closing.

@sirn-se sirn-se closed this as completed Apr 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants