略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Stomp::__destruct

2024-11-13

Stomp::__destruct

stomp_close

(PECL stomp >= 0.1.0)

Stomp::__destruct -- stomp_closeCloses stomp connection

说明

面向对象风格 (destructor):

public Stomp::__destruct()

过程化风格:

stomp_close(resource $link): bool

Closes a previously opened connection.

参数

link

仅对过程化样式:由 stomp_connect() 返回的 stomp 连接标识符。

返回值

成功时返回 true, 或者在失败时返回 false

范例

See stomp_connect().

add a noteadd a note

User Contributed Notes 1 note

up
0
vanja at removethis dizyart period com
3 years ago
Isn't it a little odd to have connect/disconnect in the constructor/destructor methods?
I have a case where the connection is presumably kept alive until the PHP process ends:

<?php
class MyStompWrapper {
    public function
doSend()
    {
       
$stomp = $this->connect(); // returns Stomp Object
       
$stomp->send('/destination', 'message', []);
       
$this->disconnect($stomp);
       
// $stomp still exists in this scope, hence, the connection is alive
   
}

    private function
disconnect(\Stomp $stompObj)
    {
       
// only unsets the local $stomp pointer, does not actually disconnect
       
unset($stomp);
    }

    private function
connect():\Stomp
   
{
       
// try-catch block omitted for example brevity
       
return new Stomp('url', 'username', 'password');
    }
}
?>

This means that, in order to handle disconnecting, I have to create and destroy the Stomp object within the same scope.

官方地址:https://www.php.net/manual/en/stomp.destruct.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3