Hướng dẫn php unique process id
I want to run a php script on background and store its PID on database. So that I can check if the particular script running or not (later). Show We can use But as per the PHP manual
...and I cannot rely on PID. My second idea is to store the process created time to the database. How can I get the current script created time? And later how can I compare with tasklist to check whether the particular script is running or not? I am running on a shared host, windows/linux environment.
BenMorel 32.6k48 gold badges170 silver badges302 bronze badges asked Jul 26, 2013 at 6:17
4 From php.net/getmypid with little modification to disable non cli access. script can be executed using Additionally use
answered Jul 26, 2013 at 6:45
PrasanthPrasanth 5,1492 gold badges28 silver badges61 bronze badges It all depends on your level of access to target machine. You can use PHP CLI, store PIDs (they are unique to particular point in time, so you won't have 2 processes with same PIDs running) and grep them in the output of answered Jul 26, 2013 at 6:32
David JashiDavid Jashi 4,4681 gold badge20 silver badges26 bronze badges 1 You can try use the PID with another id, for example: if you have a zipping job that uses a file id = 327, try to store {PID}327, and with this check if this particular job still running. Even if the PID get reused, you will not have that PID with id 327 stored, or if you restart the zipping process with this particular id 327, probabily the PID will change. But, to avoid get the same PID with this id 327, you'll have to check your database before, and then add a counter at the end of the composed id, like {PID}327_1. Hope this can help you. answered Aug 2, 2018 at 16:38
Not the answer you're looking for? Browse other questions tagged php or ask your own question.(PHP 4, PHP 5, PHP 7, PHP 8) getmypid — Gets PHP's process ID Descriptiongetmypid(): int|false ParametersThis function has no parameters. Return Values Returns the current PHP process ID, or NotesWarning Process IDs are not unique, thus they are a weak entropy source. We recommend against relying on pids in security-dependent contexts. See Also
Radu Cristescu ¶ 9 years ago
('LOCK_FILE', "/var/run/" . basename($argv[0], ".php") . ".lock"); Robert Mays Jr ¶ 11 years ago
brooke at jump dot net ¶ 18 years ago
Kevin Traas (ktraas- at -gmail dot com) ¶ 12 years ago
( 'LOCK_FILE', "/var/run/".basename( $argv[0], ".php" ).".lock" );
martijn at nowhere dot com ¶ 6 years ago
brospam at gmail dot com ¶ 9 years ago
Erickson Reyes ercbluemonday at yahoo dot com ¶ 12 years ago
$commands as $command) { eight_hf at live dot fr ¶ 10 years ago
kroczu at interia dot pl ¶ 16 years ago
function getpidinfo($pid, $ps_opt="aux"){
$ps=shell_exec("ps ".$ps_opt."p ".$pid);
Pure-PHP ¶ 17 years ago
("ProcessHandler.class.php");
wouter99999 at gmail dot com ¶ 11 years ago
james at voodoo dot co dot uk ¶ 12 years ago
pdc at example dot com ¶ 10 years ago
$result;
gabe at fijiwebdesign dot com ¶ 12 years ago
|