function make_user($user) { $prefs = $user->global_prefs; $run_on_batteries = parse_boolint($prefs, "run_on_batteries"); $run_if_user_active = parse_boolint($prefs, "run_if_user_active"); $start_hour = parse_num($prefs, "<start_hour>"); $end_hour = parse_num($prefs, "<end_hour>"); $net_start_hour = parse_num($prefs, "<net_start_hour>"); $net_end_hour = parse_num($prefs, "<net_end_hour>"); $leave_apps_in_memory = parse_boolint($prefs, "leave_apps_in_memory"); $confirm_before_connecting = parse_boolint($prefs, "confirm_before_connecting"); $hangup_if_dialed = parse_boolint($prefs, "hangup_if_dialed"); $work_buf_min_days = parse_num($prefs, "<work_buf_min_days>"); $max_cpus = parse_num($prefs, "<max_cpus>"); $cpu_scheduling_period_minutes = parse_num($prefs, "<cpu_scheduling_period_minutes>"); $disk_interval = parse_num($prefs, "<disk_interval>"); $disk_max_used_gb = parse_num($prefs, "<disk_max_used_gb>"); $disk_max_used_pct = parse_num($prefs, "<disk_max_used_pct>"); $disk_min_free_gb = parse_num($prefs, "<disk_min_free_gb>"); $vm_max_used_pct = parse_num($prefs, "<vm_max_used_pct>"); $idle_time_to_run = parse_num($prefs, "<idle_time_to_run>"); $max_bytes_sec_up = parse_num($prefs, "<max_bytes_sec_up>"); $max_bytes_sec_down = parse_num($prefs, "<max_bytes_sec_down>"); $query = "insert into puser values\n ({$user->id},\n {$user->create_time},\n '{$user->email_addr}',\n '{$user->country}',\n {$user->total_credit},\n '{$user->venue}',\n {$run_on_batteries},\n {$run_if_user_active},\n {$start_hour},\n {$end_hour},\n {$net_start_hour},\n {$net_end_hour},\n {$leave_apps_in_memory},\n {$confirm_before_connecting},\n {$hangup_if_dialed},\n {$work_buf_min_days},\n {$max_cpus},\n {$cpu_scheduling_period_minutes},\n {$disk_interval},\n {$disk_max_used_gb},\n {$disk_max_used_pct},\n {$disk_min_free_gb},\n {$vm_max_used_pct},\n {$idle_time_to_run},\n {$max_bytes_sec_up},\n {$max_bytes_sec_down})\n "; $retval = _mysql_query($query); if (!$retval) { echo _mysql_error(); } }
function do_query($query) { echo "Doing query:\n{$query}\n"; $result = _mysql_query($query); if (!$result) { echo "Failed:\n" . _mysql_error() . "\n"; } else { echo "Success.\n"; } }
function fix_profiles() { $start_id = 0; //Set this to something else if you like $profiles = _mysql_query("select * from profile where userid>{$start_id} order by userid"); echo _mysql_error(); $i = 0; while ($profile = _mysql_fetch_object($profiles)) { $i++; if ($i % 100 == 0) { //For every 100 profiles echo $profile->userid . ". "; flush(); // print out where we are //usleep(200000); } if ($profile->userid > $start_id) { fix_profile($profile); } } }
/** * Get the number of active sessions - sessions that have not expired. * * <i>The returned value does not represent the exact number of active users as some sessions may be unused * although they haven't expired.</i> * * <code> * // first, connect to a database containing the sessions table * * // include the class * require 'path/to/Zebra_Session.php'; * * // start the session * // where $link is a connection link returned by mysqli_connect * $session = new Zebra_Session($link, 'sEcUr1tY_c0dE'); * * // get the (approximate) number of active sessions * $active_sessions = $session->get_active_sessions(); * </code> * * @return integer Returns the number of active (not expired) sessions. */ public function get_active_sessions() { // call the garbage collector $this->gc(); // counts the rows from the database $result = @mysqli_fetch_assoc($this->_mysql_query(' SELECT COUNT(session_id) as count FROM ' . $this->table_name . ' ')) or die(_mysql_error()); // return the number of found rows return $result['count']; }
$func = $db_update[1]; echo "need update {$func}\n"; $updates[] = $db_update; } } if (empty($updates)) { echo "No updates needed\n"; exit; } echo "Do you want to apply these updates? (y/n) "; $x = trim(fgets(STDIN)); if ($x != 'y') { echo "OK - see db_update.php to do manual updates,\nor run this script again later.\n"; exit; } if ($argc > 1) { echo "\nWarning: you are upgrading only web or server code,\nbut these updates may affect the other code as well.\nWe recommend that you run 'upgrade' again to upgrade both parts of the code.\n\n"; } db_init_cli(); foreach ($updates as $update) { list($rev, $func) = $update; echo "performing update {$func}\n"; call_user_func($func); $e = _mysql_error(); if ($e) { echo "\nWARNING: database upgrade failed.\nMySQL error message: {$e}\nPlease find the update queries in html/ops/db_update.php\nand perform them manually.\nWhen done, edit PROJECT_DIR/db_revision so that it contains the line\n{$rev}\n\n"; break; } file_put_contents("../../db_revision", $rev); } echo "All done.\n";