Skip to content

Instantly share code, notes, and snippets.

@Rpsl
Created September 10, 2012 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rpsl/3689563 to your computer and use it in GitHub Desktop.
Save Rpsl/3689563 to your computer and use it in GitHub Desktop.
PHP check zombie process
<?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