要在 Fedeora 11 及以上版本使用 posix_getpid,您必須安裝 php-process
# yum install php-process
(PHP 4, PHP 5, PHP 7, PHP 8)
posix_getpid — 回傳目前的行程識別碼
此函式沒有參數。
以 int 型態回傳識別碼。
範例 #1 posix_getpid() 的使用範例
<?php
echo posix_getpid(); //8805
?>
要在 Fedeora 11 及以上版本使用 posix_getpid,您必須安裝 php-process
# yum install php-process
自從將 fedora 10 升級到 12 後,我發現 posix_getpid() 消失了,而且沒有預設編譯進去,正如這裡所述。
結果發現它已被移至 php-process 套件中。
只需執行「yum install php-process」,一切就恢復正常了。
希望這能為其他人節省半小時的研究時間。
如果您的系統不支援 posix 或在 Windows 中,您可以使用以下程式碼
<?php
if (!function_exists('posix_getpid')) {
function posix_getpid() {
return getmypid();
}
}
一個後備函式
<?php
function get_current_id() {
if(!function_exists(posix_getpid()))
return getmypid();
return posix_getpid();
}
?>