Forum Moderators: coopster
<?php
function fill_online() {
global $USER, GET_CONFIG;
$query = "SELECT * FROM online WHERE `session_id` = '" . session_id() . "'";
$result = mysql_query( $query );
$ip = $_SERVER['REMOTE_ADDR'];
$page = $_SERVER['REQUEST_URI'];
$browser = $_SERVER['HTTP_USER_AGENT'];
if( $result && mysql_num_rows( $result ) )
{
$user_field = '';
if($USER!= '') {
$user_field = "`user`='$USER',";
}
else {
$user_field = "`user`='',";
}
$query = "UPDATE `online`
SET
$user_field
`browser` = '$browser',
`ip` = ' $ip',
`time` = '".date("YmdHi")."'
WHERE `session_id` = '" . session_id() . "'";
mysql_query($query);
}
else {
if ($USER!= '') {
$query = "INSERT INTO `online` (`session_id`, `user`, `time`, `ip`, `browser`, `page`)
VALUES('".session_id()."','$USER','". date( "YmdHi" )."','$ip','$browser','$page')";
}
else {
$query = "INSERT INTO `online` (`session_id`, `time`, `ip`, `browser`, `page`)
VALUES('".session_id()."', '". date( "YmdHi" )."','$ip','$browser','$page')";
}
mysql_query($query);
}
@mysql_free_result($result);
//DELETE
$now = date("YmdHi"); // yyyymmddhhmm, ex. 200009021431
$timer_ago = date("YmdHi", mktime(date("H"), date("i") - $GET_CONFIG['max_time_online'], 0,
date("m"), date("d"), date("Y")));
$query = "DELETE FROM `online` WHERE `time` < '" . $timer_ago ."'";
mysql_query($query);
}
?>
can anyone suggest me how to tweak this code?
Yes above code works very fine with about 300+ users online.. at a time.. but whenever online users increase up to 400.. I get mysql error table "Table online is crashed" so all I have to login into cpanel and repair online table.
There should be a performance issue. because it keeps check online table.. Just wondering if there is any thing PHP where I can store global variable in server memory..
like static or if you have knowledge of ASP then there is Application object which resides in server memory.. If I found something like this then table crash wont happen
As far as I know this is due to too many table queries/deletion from online table
this would cause corruption, I've had the same problem a couple times, up the number of max_connections and things are ok.
You could maybe tone down the number of times it hits the db, maybe store a timestamp in the session and only have it write every x number of minutes, make x = to whatever lightens the load down to manageable levels
>> still new user
hehe, you're just the quiet type ;)