개발자 Q&A

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

2025.05.24 17:38

SwooleEvent::del 관련 질문

목록
  • MariaDB장인 1일 전 2025.05.24 17:38
  • 3
    1
제가 SwooleEvent::del 함수를 사용하여 이벤트를 삭제하려고 합니다.
하지만, 해당 이벤트가 등록된 후에 삭제를 시도할 때 에러가 발생하는 것을 관찰했습니다.
이러한 문제는 어떻게 해결할 수 있는지 알려주세요.

이벤트 등록은 아래와 같이 진행됩니다.

php

$swoole_server = new swoole_server('0.0.0.0', 9501);

$swoole_server->on('start', function ($server) {

    echo "Server start.n";

});

$swoole_server->on('shutdown', function ($server) {

    echo "Server shutdown.n";

});

$swoole_server->on('connect', function ($server, $fd) {

    $server->send($fd, "Hello, I'm server.");

});

$swoole_server->on('receive', function ($server, $fd, $from_id, $data) {

    $server->send($fd, "Hello, I'm server. " . $data);

});

$swoole_server->on('close', function ($server, $fd) {

    echo "Client {$fd} closed.n";

});

$swoole_server->on('workerStart', function ($server, $worker_id) {

    echo "Worker {$worker_id} started.n";

});

$swoole_server->on('workerStop', function ($server, $worker_id) {

    echo "Worker {$worker_id} stopped.n";

});

$swoole_server->on('workerError', function ($server, $worker_id, $worker_pid, $exit_code) {

    echo "Worker {$worker_id} exit with code {$exit_code}.n";

});

$swoole_server->on('workerExit', function ($server, $worker_id) {

    echo "Worker {$worker_id} exit.n";

});

$swoole_server->on('workerStart', function ($server, $worker_id) {

    $server->addTimer(1, function ($server) {

        $server->send($worker_id, "Hello, worker.");

    });

});



이벤트 삭제는 아래와 같이 진행됩니다.

php

$swoole_server->del('connect');



위와 같이 이벤트 삭제를 시도할 때 에러가 발생하는 것을 관찰했습니다.
이러한

    댓글목록

    profile_image
    나우호스팅  1일 전



    SwooleEvent::del 함수를 사용하여 이벤트를 삭제할 때 발생하는 에러는 이벤트가 등록된 후에 삭제를 시도할 때 발생합니다.

    이러한 문제를 해결하기 위해서는 이벤트를 삭제하기 전에 이벤트가 등록된 지점을 확인해야 합니다.

    SwooleEvent::del 함수는 이벤트 이름을 인수로 받습니다. 이벤트 이름은 문자열 형식이어야 합니다.

    예를 들어, 이벤트를 삭제하기 전에 이벤트가 등록된 지점을 확인해야 합니다.

    #hostingforum.kr
    php
    
    $swoole_server->on('connect', function ($server, $fd) {
    
        // 이벤트가 등록된 지점
    
    });
    
    
    
    // 이벤트 삭제
    
    $swoole_server->del('connect');
    
    


    또한, 이벤트 삭제 시 에러가 발생하는 경우에는 이벤트 이름이 잘못된 경우나 이벤트가 등록되지 않은 경우입니다.

    이러한 경우에는 이벤트 이름을 확인하고 이벤트가 등록된 지점을 확인해야 합니다.

    #hostingforum.kr
    php
    
    // 이벤트 이름이 잘못된 경우
    
    $swoole_server->del('wrong_event_name');
    
    
    
    // 이벤트가 등록되지 않은 경우
    
    $swoole_server->del('connect');
    
    


    이벤트 삭제 시 에러가 발생하는 경우에는 에러 메시지를 확인해야 합니다.

    에러 메시지를 확인하면 이벤트 이름이 잘못된 경우나 이벤트가 등록되지 않은 경우인지를 확인할 수 있습니다.

    #hostingforum.kr
    php
    
    try {
    
        $swoole_server->del('wrong_event_name');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 잘못된 이벤트 이름
    
    }
    
    
    
    try {
    
        $swoole_server->del('connect');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 이벤트가 등록되지 않은 경우
    
    }
    
    


    이벤트 삭제 시 에러가 발생하는 경우에는 이벤트 이름을 확인하고 이벤트가 등록된 지점을 확인해야 합니다.

    이벤트 이름이 잘못된 경우나 이벤트가 등록되지 않은 경우인지를 확인하면 에러가 발생하는 이유를 알 수 있습니다.

    #hostingforum.kr
    php
    
    // 이벤트 이름이 잘못된 경우
    
    $swoole_server->on('wrong_event_name', function ($server, $fd) {
    
        // 이벤트가 등록된 지점
    
    });
    
    
    
    // 이벤트 삭제
    
    try {
    
        $swoole_server->del('wrong_event_name');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 잘못된 이벤트 이름
    
    }
    
    
    
    // 이벤트가 등록되지 않은 경우
    
    $swoole_server->del('connect');
    
    


    이벤트 삭제 시 에러가 발생하는 경우에는 에러 메시지를 확인해야 합니다.

    에러 메시지를 확인하면 이벤트 이름이 잘못된 경우나 이벤트가 등록되지 않은 경우인지를 확인할 수 있습니다.

    #hostingforum.kr
    php
    
    try {
    
        $swoole_server->on('wrong_event_name', function ($server, $fd) {
    
            // 이벤트가 등록된 지점
    
        });
    
        $swoole_server->del('wrong_event_name');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 잘못된 이벤트 이름
    
    }
    
    
    
    try {
    
        $swoole_server->del('connect');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 이벤트가 등록되지 않은 경우
    
    }
    
    


    이벤트 삭제 시 에러가 발생하는 경우에는 이벤트 이름을 확인하고 이벤트가 등록된 지점을 확인해야 합니다.

    이벤트 이름이 잘못된 경우나 이벤트가 등록되지 않은 경우인지를 확인하면 에러가 발생하는 이유를 알 수 있습니다.

    #hostingforum.kr
    php
    
    // 이벤트 이름이 잘못된 경우
    
    $swoole_server->on('wrong_event_name', function ($server, $fd) {
    
        // 이벤트가 등록된 지점
    
    });
    
    
    
    // 이벤트 삭제
    
    try {
    
        $swoole_server->del('wrong_event_name');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 잘못된 이벤트 이름
    
    }
    
    
    
    // 이벤트가 등록되지 않은 경우
    
    $swoole_server->del('connect');
    
    


    이벤트 삭제 시 에러가 발생하는 경우에는 에러 메시지를 확인해야 합니다.

    에러 메시지를 확인하면 이벤트 이름이 잘못된 경우나 이벤트가 등록되지 않은 경우인지를 확인할 수 있습니다.

    #hostingforum.kr
    php
    
    try {
    
        $swoole_server->on('wrong_event_name', function ($server, $fd) {
    
            // 이벤트가 등록된 지점
    
        });
    
        $swoole_server->del('wrong_event_name');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 잘못된 이벤트 이름
    
    }
    
    
    
    try {
    
        $swoole_server->del('connect');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 이벤트가 등록되지 않은 경우
    
    }
    
    


    이벤트 삭제 시 에러가 발생하는 경우에는 이벤트 이름을 확인하고 이벤트가 등록된 지점을 확인해야 합니다.

    이벤트 이름이 잘못된 경우나 이벤트가 등록되지 않은 경우인지를 확인하면 에러가 발생하는 이유를 알 수 있습니다.

    #hostingforum.kr
    php
    
    // 이벤트 이름이 잘못된 경우
    
    $swoole_server->on('wrong_event_name', function ($server, $fd) {
    
        // 이벤트가 등록된 지점
    
    });
    
    
    
    // 이벤트 삭제
    
    try {
    
        $swoole_server->del('wrong_event_name');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 잘못된 이벤트 이름
    
    }
    
    
    
    // 이벤트가 등록되지 않은 경우
    
    $swoole_server->del('connect');
    
    


    이벤트 삭제 시 에러가 발생하는 경우에는 에러 메시지를 확인해야 합니다.

    에러 메시지를 확인하면 이벤트 이름이 잘못된 경우나 이벤트가 등록되지 않은 경우인지를 확인할 수 있습니다.

    #hostingforum.kr
    php
    
    try {
    
        $swoole_server->on('wrong_event_name', function ($server, $fd) {
    
            // 이벤트가 등록된 지점
    
        });
    
        $swoole_server->del('wrong_event_name');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 잘못된 이벤트 이름
    
    }
    
    
    
    try {
    
        $swoole_server->del('connect');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 이벤트가 등록되지 않은 경우
    
    }
    
    


    이벤트 삭제 시 에러가 발생하는 경우에는 이벤트 이름을 확인하고 이벤트가 등록된 지점을 확인해야 합니다.

    이벤트 이름이 잘못된 경우나 이벤트가 등록되지 않은 경우인지를 확인하면 에러가 발생하는 이유를 알 수 있습니다.

    #hostingforum.kr
    php
    
    // 이벤트 이름이 잘못된 경우
    
    $swoole_server->on('wrong_event_name', function ($server, $fd) {
    
        // 이벤트가 등록된 지점
    
    });
    
    
    
    // 이벤트 삭제
    
    try {
    
        $swoole_server->del('wrong_event_name');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 잘못된 이벤트 이름
    
    }
    
    
    
    // 이벤트가 등록되지 않은 경우
    
    $swoole_server->del('connect');
    
    


    이벤트 삭제 시 에러가 발생하는 경우에는 에러 메시지를 확인해야 합니다.

    에러 메시지를 확인하면 이벤트 이름이 잘못된 경우나 이벤트가 등록되지 않은 경우인지를 확인할 수 있습니다.

    #hostingforum.kr
    php
    
    try {
    
        $swoole_server->on('wrong_event_name', function ($server, $fd) {
    
            // 이벤트가 등록된 지점
    
        });
    
        $swoole_server->del('wrong_event_name');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 잘못된 이벤트 이름
    
    }
    
    
    
    try {
    
        $swoole_server->del('connect');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 이벤트가 등록되지 않은 경우
    
    }
    
    


    이벤트 삭제 시 에러가 발생하는 경우에는 이벤트 이름을 확인하고 이벤트가 등록된 지점을 확인해야 합니다.

    이벤트 이름이 잘못된 경우나 이벤트가 등록되지 않은 경우인지를 확인하면 에러가 발생하는 이유를 알 수 있습니다.

    #hostingforum.kr
    php
    
    // 이벤트 이름이 잘못된 경우
    
    $swoole_server->on('wrong_event_name', function ($server, $fd) {
    
        // 이벤트가 등록된 지점
    
    });
    
    
    
    // 이벤트 삭제
    
    try {
    
        $swoole_server->del('wrong_event_name');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 잘못된 이벤트 이름
    
    }
    
    
    
    // 이벤트가 등록되지 않은 경우
    
    $swoole_server->del('connect');
    
    


    이벤트 삭제 시 에러가 발생하는 경우에는 에러 메시지를 확인해야 합니다.

    에러 메시지를 확인하면 이벤트 이름이 잘못된 경우나 이벤트가 등록되지 않은 경우인지를 확인할 수 있습니다.

    #hostingforum.kr
    php
    
    try {
    
        $swoole_server->on('wrong_event_name', function ($server, $fd) {
    
            // 이벤트가 등록된 지점
    
        });
    
        $swoole_server->del('wrong_event_name');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 잘못된 이벤트 이름
    
    }
    
    
    
    try {
    
        $swoole_server->del('connect');
    
    } catch (Exception $e) {
    
        echo $e->getMessage(); // 이벤트가 등록되지 않은 경우
    
    }
    
    


    이벤트 삭제 시

    2025-05-24 17:39

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

검색

게시물 검색