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].
We can use getmypid
to get current PID.
But as per the PHP manual
Process IDs are not unique, thus they are a weak entropy source. We recommend against relying on pids in security-dependent contexts.
...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 /usr/bin/php script.php
.
Additionally use nohup /usr/bin/php script.php > nohup.out &
to launch a nohup
process in background.
#!/usr/bin/php