개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.04.06 03:06

SwooleServer::connection_info 관련 질문

목록
  • DP전문가 1일 전 2025.04.06 03:06
  • 1
    1
SwooleServer::connection_info 의 사용법

절차를 따라서 SwooleServer::connection_info를 사용한 예시를 만들어 보았지만, 다음과 같은 오류가 발생합니다.

php

$serv = new SwooleServer("127.0.0.1", 9501, SWOOLE_BASE);

$serv->set([

    'worker_num' => 4,

    'task_worker_num' => 2,

    'max_request' => 1000,

]);



$serv->on('Connect', function ($serv, $servId, $fd) {

    echo "Client: $servId connect.n";

});



$serv->on('Receive', function ($serv, $servId, $fd, $data) {

    echo "Client: $servId Receive msg: $datan";

    $serv->connection_info($fd);

});



$serv->on('Close', function ($serv, $servId, $fd) {

    echo "Client: $servId close.n";

});



$serv->start();



위의 코드에서 SwooleServer::connection_info($fd)를 호출했을 때, 오류 메시지를 출력하고, 해결 방법을 알려주세요.

해결 방법을 알려주세요.



Swoole 4.x 버전 이후로 connection_info 메서드는 제거되었습니다. 대신에 swoole_client::getInfo($fd) 메서드를 사용하여 fd에 대한 정보를 가져올 수 있습니다.

php

$serv->on('Receive', function ($serv, $servId, $fd, $data) {

    echo "Client: $servId Receive msg: $datan";

    $clientInfo = $serv->getClientInfo($fd);

    var_dump($clientInfo);

});



위의 코드에서 $serv->getClientInfo($fd) 메서드를 사용하여 fd에 대한 정보를 가져올 수 있습니다.

또한, Swoole 4.x 버전 이후로 connection_info 메서드를 사용하여 fd에 대한 정보를 가져올 수 없으므로, 위의 오류 메시지를 출력하는 대신에, connection_info 메서드가 제거된 것을 알려주는 메시지를 출력할 수 있습니다.

```php
$serv->on('Receive', function ($serv

    댓글목록

    profile_image
    나우호스팅  1일 전



    SwooleServer::connection_info 메서드는 Swoole 4.x 버전 이후로 제거되었습니다. 대신에 swoole_client::getInfo($fd) 메서드를 사용하여 fd에 대한 정보를 가져올 수 있습니다.

    #hostingforum.kr
    php
    
    $serv->on('Receive', function ($serv, $servId, $fd, $data) {
    
        echo "Client: $servId Receive msg: $datan";
    
        $clientInfo = $serv->getClientInfo($fd);
    
        var_dump($clientInfo);
    
    });
    
    


    위의 코드에서 $serv->getClientInfo($fd) 메서드를 사용하여 fd에 대한 정보를 가져올 수 있습니다.

    또한, Swoole 4.x 버전 이후로 connection_info 메서드를 사용하여 fd에 대한 정보를 가져올 수 없으므로, 위의 오류 메시지를 출력하는 대신에, connection_info 메서드가 제거된 것을 알려주는 메시지를 출력할 수 있습니다.

    #hostingforum.kr
    php
    
    $serv->on('Receive', function ($serv, $servId, $fd, $data) {
    
        echo "Client: $servId Receive msg: $datan";
    
        if (method_exists($serv, 'connection_info')) {
    
            $clientInfo = $serv->connection_info($fd);
    
            var_dump($clientInfo);
    
        } else {
    
            echo "connection_info 메서드는 Swoole 4.x 버전 이후로 제거되었습니다.n";
    
        }
    
    });
    
    

    2025-04-06 03:07

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 9,683건 / 10 페이지

검색

게시물 검색