
Swoole_last_error 함수를 사용하여 에러를 처리할 때, 에러 메시지를 정확하게 파악하려면 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
$lastError = swoole_last_error();
$errorInfo = swoole_strerror($lastError);
위 코드를 통해 에러 메시지를 얻을 수 있습니다.
만약 에러가 발생했을 때, 에러 코드를 얻으려면 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
$lastError = swoole_last_error();
위 코드를 통해 에러 코드를 얻을 수 있습니다.
예를 들어, 다음과 같은 코드를 작성했을 때, 에러가 발생했을 때 에러 메시지를 얻기 위해 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
use SwooleServer;
$server = new Server('0.0.0.0', 9501, SWOOLE_BASE);
$server->on('connect', function ($server, $fd) {
echo "Client {$fd} connected.n";
});
$server->on('receive', function ($server, $fd, $from_id, $data) {
echo "Client {$fd} received message: {$data}n";
});
$server->on('close', function ($server, $fd) {
echo "Client {$fd} closed.n";
});
try {
$server->start();
} catch (Exception $e) {
$lastError = swoole_last_error();
$errorInfo = swoole_strerror($lastError);
echo "에러 메시지: {$errorInfo}n";
}
위 코드를 통해 에러 메시지를 얻을 수 있습니다.
2025-07-14 09:49