略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: posix_getpid

2024-11-15

posix_getpid

(PHP 4, PHP 5, PHP 7, PHP 8)

posix_getpid返回当前进程 id

说明

posix_getpid(): int

Return the process identifier of the current process. 返回当前进程的 id

参数

此函数没有参数。

返回值

返回进程 id 号,是整型(int)。

范例

示例 #1 posix_getpid() 的使用例子

<?php
echo posix_getpid(); //8805
?>

参见

  • posix_kill() - Send a signal to a process
  • POSIX man page GETPID(2)
add a noteadd a note

User Contributed Notes 5 notes

up
5
zapolski at gmail dot com
11 years ago
In order to use posix_getpid on Fedeora 11 and up you have to install php-process

# yum install php-process
up
4
Yzmir Ramirez
10 years ago
You can also try using getmypid() instead.
up
1
andy at haveland dot com
12 years ago
Since upgrading fedora 10 to 12, I discovered that posix_getpid() disappeared and not compiled in by default, as it specifies here.

It turns out that it had been moved into package php-process.

Just do "yum install php-process", and all should be sweet again.

Hope this saves someone half an hour of research.
up
0
ia dot beladel at protonmail dot com
1 month ago
A fall back function:
<?php
   
function get_current_id() {
        if(!
function_exists(posix_getpid()))
            return
getmypid();
       
        return
posix_getpid();
    }
?>
up
0
victor at gmail dot com
2 years ago
You can use this code in windows or if you system has no posix support:

<?php
if (!function_exists('posix_getpid')) {
    function
posix_getpid() {
        return
getmypid();
    }
}

官方地址:https://www.php.net/manual/en/function.posix-getpid.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3