PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

getmyuid> <getmyinode
Last updated: Fri, 05 Sep 2008

view this page in

getmypid

(PHP 4, PHP 5)

getmypidProzess-Id eines Scripts

Beschreibung

int getmypid ( void )

Liefert die Prozess-ID unter der das Skript ausgeführt wird.

Rückgabewerte

Liefert die Prozess-ID unter der das Skript ausgeführt wird, oder FALSE bei Fehlern

Anmerkungen

Warnung

Prozess-IDs sind nicht eindeutig, sie sind daher eine schwache Entropiequelle. Wir raten davon ab sich in sicherheitsrelevanten Bereichen auf Prozess-IDs zu verlassen.



getmyuid> <getmyinode
Last updated: Fri, 05 Sep 2008
 
add a note add a note User Contributed Notes
getmypid
kroczu at interia dot pl
19-Dec-2005 04:59
<?php
/*

mixed getpidinfo(mixed pid [, string system_ps_command_options])

this function gets PID-info from system ps command and return it in useful assoc-array,
or return false and trigger warning if PID doesn't exists

$pidifo=getpidinfo(12345);

print_r($pidifo);

Array
(
    [USER] => user
    [PID] => 12345
    [%CPU] => 0.0
    [%MEM] => 0.0
    [VSZ] => 1720
    [RSS] => 8
    [TT] => ??
    [STAT] => Is
    [STARTED] => 6:00PM
    [TIME] => 0:00.01
    [COMMAND] => php someproces.php > logfile
)

*/

//////////////////////////////////////////////

function getpidinfo($pid, $ps_opt="aux"){

  
$ps=shell_exec("ps ".$ps_opt."p ".$pid);
  
$ps=explode("\n", $ps);
  
   if(
count($ps)<2){
     
trigger_error("PID ".$pid." doesn't exists", E_USER_WARNING);
      return
false;
   }

   foreach(
$ps as $key=>$val){
     
$ps[$key]=explode(" ", ereg_replace(" +", " ", trim($ps[$key])));
   }

   foreach(
$ps[0] as $key=>$val){
     
$pidinfo[$val] = $ps[1][$key];
      unset(
$ps[1][$key]);
   }
  
   if(
is_array($ps[1])){
     
$pidinfo[$val].=" ".implode(" ", $ps[1]);
   }
   return
$pidinfo;
}

?>
Pure-PHP
21-Mar-2005 02:26
You can use this function also to avoid more than one instance of your app.

You can also use this class.
http://www.pure-php.de/node/20

Usage:

<?php

inlude
("ProcessHandler.class.php");

if(
ProcessHandler::isActive()){
   die(
"Already running!\n";);
}else{
  
ProcessHandler::activate();
  
//run my app
}

?>
brooke at jump dot net
24-Oct-2003 05:49
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.

getmyuid> <getmyinode
Last updated: Fri, 05 Sep 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites