Created
September 10, 2012 08:03
-
-
Save Rpsl/3689563 to your computer and use it in GitHub Desktop.
PHP check zombie process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Проверка на зависший процесс | |
$pid = '/tmp/filestart.pid'; | |
$timeout = 3 * 60 * 60; | |
if ( is_file( $pid ) ) | |
{ | |
$pidInfo = explode( '|', file_get_contents( $pid ) ); | |
if ( isset( $pidInfo[1] ) AND $pidInfo[1] + $timeout > time() ) | |
{ | |
//Ещё невышел таймаут | |
exit(); | |
} | |
if ( isset( $pidInfo[0] ) ) | |
{ | |
`kill -9 {$pidInfo[0]}`; | |
} | |
} | |
// С одной стороны вместо time() можно использовать filemtime(), но он возвращает дату модификации, | |
// а так мы уверены что работаем с датой старта. | |
file_put_contents( $pid, posix_getpid() . '|' . time() ); | |
//<SCRIPT> | |
unlink( $pid ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment