2024 日本 PHP 研討會

pcntl_get_last_error

(PHP 5 >= 5.3.4, PHP 7, PHP 8)

pcntl_get_last_error擷取最後一個失敗的 pcntl 函式所設定的錯誤碼

說明

pcntl_get_last_error(): int

擷取最後一個失敗的 pcntl 函式所設定的錯誤碼 (errno)。與錯誤碼相關聯的系統錯誤訊息可以使用 pcntl_strerror() 檢查。

參數

此函式沒有參數。

回傳值

返回最後一個失敗的 pcntl 函式所設定的錯誤碼 (errno)。如果沒有錯誤,則返回 0。

範例

範例 #1 pcntl_get_last_error() 範例

此範例將嘗試在沒有子行程存在的情況下等待子行程,然後印出相應的錯誤訊息。

<?php
$pid
= pcntl_wait($status);
if (
$pid === -1) {
$errno = pcntl_get_last_error();
$message = pcntl_strerror($errno);
fwrite(STDERR, 'pcntl_wait 失敗,錯誤碼為 ' . $errno
. ': ' . $message . PHP_EOL);
}

上述範例將輸出類似以下的內容

pcntl_wait failed with errno 10: No child processes

參見

新增筆記

使用者貢獻的筆記

此頁面沒有使用者貢獻的筆記。
To Top