- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
if(file_exists('./daemon.php') & isset($_GET['stop'])){
rename('./daemon.php', './daemon.php~');
sleep(3);
header('Location: http://'.$_SERVER[HTTP_HOST]);
}elseif(isset($_GET['restart'])){
include('./lib.inc');
@rename('./daemon.php', './daemon.php~');
sleep(3);
rename('./daemon.php~', './daemon.php');
ping('daemon.php');
sleep(3);
header('Location: http://'.$_SERVER[HTTP_HOST]);
}
echo '<a href="/?restart" class="button">Start/Restart</a> ';
if(file_exists('./daemon.php'))
echo '<a href="/?stop" class="button">Stop</a>';
?><br>
<div class="display">-</div>
<script type="text/javascript"><!--
var xd;
setInterval(function(){
xd&&xd.abort();
xd = new XMLHttpRequest();
xd.onreadystatechange = function(){
if(xd.readyState == 4){
document.querySelector(".display").textContent = xd.responseText;
}
}
xd.open('GET', '/display.txt', true);
xd.send();
}, 3000);
//--></script>
daemon.php:
if(date('his')-file_get_contents('./date')<2)
exit;
file_put_contents('./date', date('his'));
include('./lib.inc');
$f=fopen('./lock', 'w+');
flock($f, LOCK_EX);
ping('core.php');
sleep(3);
ping('daemon.php');
usleep(200);
ping('daemon.php');
usleep(200);
flock($f, LOCK_UN);
core.php:
ini_set('display_errors', 'on');
error_reporting(E_ALL);
ini_set('html_errors', 'off');
$xreservedbasedir=__DIR__;
$xreservedtmpbuf=str_repeat('x', 1024 * 3);
function ob_write($buffer){
unset($GLOBALS['xreservedtmpbuf']);
file_put_contents($GLOBALS['xreservedbasedir'].'/display.txt', $buffer, LOCK_EX);
}
ob_start('ob_write');
include('./script.php');
script.php:
echo date("Y.m.d h:i:s"); //любой код, который исполняет демон
lib.inc:
function ping($action){
$h=$_SERVER[HTTP_HOST];
$http=fsockopen($h, 80, $e1, $e2, 1);
if($http){
fwrite($http,
'GET /'.$action.' HTTP/1.1'."\r\n".
'Accept: */*'."\r\n".
'Host: '.$h."\r\n\r\n"
);
fclose($http);
}
}