What is the difference between posix_getpid() and getmypid()? It appears that they're implemented differently. I wrote this quick test script:
<?php
$max = 1000000;
$arr = array();
$a_0 = microtime(TRUE);
for ($i=0; $i<$max; $i++) {
$arr[] = getmypid();
}
$a_1 = microtime(TRUE);
$arr = array();
$b_0 = microtime(TRUE);
for ($i=0; $i<$max; $i++) {
$arr[] = posix_getpid();
}
$b_1 = microtime(TRUE);
$diff_a = $a_1 - $a_0;
$diff_b = $b_1 - $b_0;
echo "A: $diff_a, B: $diff_b: " . ($diff_b / $diff_a) . "\n";
?>
I ran this a number of times, and time got results similar to this:
A: 1.1289880275726, B: 1.1726188659668: 1.0386459708417
So it's around 4% faster to use getmypid().
Wednesday, December 19, 2007
Gets PHP's process ID
POSTED BY
Oriol
AT
7:02 AM