note 36859 modified in function.getmypid by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 00:26:58 +0000 |
| Subject: | note 36859 modified in function.getmypid by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-141843@lists.php.net to get a copy of this message | ||
One good use for this is deciding on a concurrency-safe temporary file or directory name. You can be
assured that no two processes on the same server have the same PID, so this is enough to avoid
collisions. For example:
<?php
$tmpfile = "/tmp/foo_".getmypid();
// Use $tmpfile...
// Use $tmpfile...
// Use $tmpfile...
unlink ($tmpfile);
?>
If you are sharing /tmp over the network (which is odd....) then you can, of course, mix in the PHP
server's IP address.
--was--
One good use for this is deciding on a concurrency-safe temporary file or directory name. You can be
assured that no two processes on the same server have the same PID, so this is enough to avoid
collisions. For example:
$tmpfile = "/tmp/foo_".getmypid();
// Use $tmpfile...
// Use $tmpfile...
// Use $tmpfile...
unlink ($tmpfile);
If you are sharing /tmp over the network (which is odd....) then you can, of course, mix in the PHP
server's IP address.
http://php.net/manual/en/function.getmypid.php