- , . . PHP GD.
-, , - :
mkdir liveusers
PHP script ( vlive.php, ) (, * nix, system(), passthru() exec (), ). , , IP + SessionID concat'd :
<?php
exec("touch ". $_SERVER['DOCUMENT_ROOT']."/liveusers/". md5($_SERVER['REMOTE_ADDR'].session_id()));
JPEG, (). 1x1 pixel.jpg - /images/directory, - :
$NewImage = imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT']. "/images/pixel.jpg");
header("Content-type: image/jpeg");
imagejpeg($NewImage);
?>
PHP, HTML-, :
<img src="/vlive.php" alt="Imagination!" />
PHP , . , "" .
, , , , , touch, , , .
:
PHP script ( readvlive.php):
<?php
$livenum = system("find ".$_SERVER['DOCUMENT_ROOT']."/liveusers/ -type f -amin +10 | wc -l");
echo "Live Visitors: ". $livenum;
?>
HTML-, :
<?php include($_SERVER['DOCUMENT_ROOT']. "/readvlive.php"); ?>
, , , 10 . ...
, , , , . PrototypeJS (Google it), AJAX, <head></head>
<script src="/js/prototype.js" type="text/javascript"></script>
</body>.
<span id="live_users_count"> </span>
<script type="text/javascript">
<!--
Event.observe(window, 'load', function() {
if($('live_users_count')) {
new Ajax.Updater('live_users_count','/readvlive.php');
}
}
-->
</script>
.. . , find, APC - .
APC 3.1.4:
<?php
if(apc_exists('livenum')){
$livenum = apc_fetch('livenum');echo $livenum;
} else {
$livenum = system("find ".$_SERVER['DOCUMENT_ROOT']."/liveusers/ -type f -amin +10 | wc -l");
apc_add('livenum',$livenum,30);
}
?>
APC 3.0.13 :
<?php
if($livenum = apc_fetch('livenum')){
echo $livenum;
} else {
$livenum = system("find ".$_SERVER['DOCUMENT_ROOT']."/liveusers/ -type f -amin +10 | wc -l");
apc_add('livenum',$livenum,30);
}
?>
APC 30 , 10 , find . .: P
crontab..
script (/root/deloverhead.sh):
#!/bin/sh
find "/path/to/liveusers/ -type f -amin +60 -exec rm {} \;
Crontab (every hour):
0 * * * * /root/deloverhead.sh >/dev/null 2>&1
Have fun, sorry, I can explain things weird .: P