Sinds we een eigen server hebben voor ons spel, www.hetpaardenspel.nl en de CPU load 80% is.
Vroeg ik mij af wat jullie van de scripting vinden. Onze Dual Opteron 165 verwerkt 500 queries per seconde. Best veel dus.
:D Help dus welkom.
<?php
class db {
var $link_id = 0;
var $query_id = 0;
var $record = array();
var $queries = array();
var $errdesc = "";
var $errno = 0;
var $show_error = 1;
var $phpversion = 1;
var $server = "";
var $user = "";
var $password = "";
var $database = "";
var $appname = "Het Paardenspel";
function db($server,$user,$password,$database,$phpversion=4) {
$this->server=$server;
$this->user=$user;
$this->password=$password;
$this->database=$database;
$this->phpversion=$phpversion;
$this->connect();
$this->querys=array();
}
function connect() {
$this->link_id=mysql_connect($this->server,$this->user,$this->password);
if (!$this->link_id) $this->error("Link-ID == false, connect failed");
if ($this->database!="") $this->select_db($this->database);
}
function close() {
return @mysql_close($this->link_id) or $this->error(DATABASE_CLASS_CLOSE);
}
function getMicrotime()
{
list($usec, $sec) = explode( " ", microtime());
return ((float) $usec + (float) $sec);
}
function geterrdesc() {
$this->error=mysql_error();
return $this->error;
}
function geterrno() {
$this->errno=mysql_errno();
return $this->errno;
}
function select_db($database="") {
if ($database!="") $this->database=$database;
if(!@mysql_select_db($this->database, $this->link_id)) $this->error("cannot use database ".$this->database);
}
function query($query_string,$limit=0,$offset=0) {
if($limit!=0) $query_string.=" LIMIT $offset, $limit";
$this->queries[]="$query_string";
$this->querys[]=$sql;
$startTime = $this->getMicrotime();
$this->query_id = mysql_query($query_string,$this->link_id);
$endTime = $this->getMicrotime();
$this->queryTime+=$endTime-$startTime;
if (!$this->query_id) $this->error("Invalid SQL: ".$query_string);
return $this->query_id;
}
function query1($query_string) {
$this->queries[]="$query_string";
$this->querys[]=$sql;
$startTime = $this->getMicrotime();
$this->query_id = mysql_query($query_string,$this->link_id);
$endTime = $this->getMicrotime();
$this->queryTime+=$endTime-$startTime;
if (!$this->query_id) $this->error("Invalid SQL: ".$query_string);
return $this->query_id;
}
function unbuffered_query($query_string,$LOW_PRIORITY=0) {
if($this->phpversion<406) return $this->query($query_string);
else {
if($LOW_PRIORITY==1) $query_string=substr($query_string,0,6)." LOW_PRIORITY".substr($query_string,6);
$this->queries[]="unbuffered: $query_string";
$this->query_id = mysql_unbuffered_query($query_string,$this->link_id);
if (!$this->query_id) $this->error("Invalid SQL: ".$query_string);
return $this->query_id;
}
}
function fetch_array($query_id=-1) {
if ($query_id!=-1) $this->query_id=$query_id;
$this->record = mysql_fetch_array($this->query_id);
return $this->record;
}
function fetch_row($query_id=-1) {
if ($query_id!=-1) $this->query_id=$query_id;
$this->record = mysql_fetch_row($this->query_id);
return $this->record;
}
function free_result($query_id=-1) {
if ($query_id!=-1) $this->query_id=$query_id;
return @mysql_free_result($this->query_id);
}
function query_first($query_string,$limit=0,$offset=0) {
$this->query($query_string,$limit,$offset);
$returnarray=$this->fetch_array($this->query_id);
$this->free_result($this->query_id);
return $returnarray;
}
function num_rows($query_id=-1) {
if ($query_id!=-1) $this->query_id=$query_id;
return mysql_num_rows($this->query_id);
}
function affected_rows() {
return mysql_affected_rows($this->link_id);
}
function insert_id() {
return mysql_insert_id($this->link_id);
}
function countQuerys(){
return count($this->querys);
}
function queryTime($round=2){
return round($this->queryTime,$round );
}
function error($errormsg) {
$this->errdesc=mysql_error();
$this->errno=mysql_errno();
$errormsg="<b>Database error in $this->appname:</b> $errormsg\n<br>";
$errormsg.="<b>mysql error:</b> $this->errdesc\n<br>";
$errormsg.="<b>mysql error number:</b> $this->errno\n<br>";
$errormsg.="<b>Date:</b> ".date("d.m.Y @ H:i")."\n<br>";
$errormsg.="<b>Script:</b> ".getenv("REQUEST_URI")."\n<br>";
$errormsg.="<b>Referer:</b> ".getenv("HTTP_REFERER")."\n<br><br>";
if($this->show_error) $errormsg = "$errormsg";
else $errormsg = "\n<!-- $errormsg -->\n";
die("</table><font face=\"Verdana\" size=2><b>SQL-DATABASE ERROR</b><br><br>".$errormsg."</font>");
}
}
$db = new db($sqlhost,$sqluser,$sqlpassword,$sqldb,$phpversion);
?>
//De pagina waar config/functies enzo staan//
<?php
// functie voor paginatijd
function getMicrotime()
{
list($usec, $sec) = explode( " ", microtime());
return ((float) $usec + (float) $sec);
}
// Pagina laadtijd start
$startpage = getMicrotime();
// Start je zelf ergens anders je sessies/cookies? Maak van de volgende twee regels dan commentaar (# of //)
session_start();
ob_start();
// mysql
$sqlhost = "";
$sqluser = "";
$sqlpassword = "";
$sqldb = "";
// Error reporting zetten we uit, het is niet echt netjes je bezoekers errors voor te schotelen
#ERROR_REPORTING(0);
// Instellingen
$loginpage = "http://www.hetpaardenspel.nl/home.php"; // Pagina waar de gebruiker heen wordt gestuurd wanneer deze is ingelogd
$forgoturl = ""; // Volledige URL naar inlogsysteem, voor activeren van wachtwoord vergeten, / aan einde
$sitenaam = "Het Paardenspel"; // Naam van je site; deze word oa. gebruikt bij het verzenden van mail
$sitemail = "[email protected]"; // Afzender van verzonden mail
require "db_class.php";
require "class_headers.php";
require "class_query.php";
require "functions.php";
require "overig/ubb.php";
?>
//Een script die gewoon op de site gebruikt word.//
<?php
include "../globals.php";
include "../safe02.php";
include "../htmltop.php";
?>
<table border="0" cellpadding="0" cellspacing="0" class="hoi">
<tr>
<td colspan="3" height="100" align="center" width="100%" valign="top">
<?php
include "../top.php";
?>
</td>
</tr>
<tr>
<td width="150" align="center" valign="top">
<?php
include "../menu01.php";
?>
</td>
<td align="center" width="100%" valign="top">
<?php
$user_id = $_SESSION['user_id'];
// spring les geven
if(isset($_POST[nee]))
{
header("location:../overig/opleiding.php");
}
// Pagina alleen toegankelijk maken voor instructie
if($row[status] != 1)
{
die("Wordt aan gewerkt!");
}
$query = "SELECT * FROM instructie WHERE user='$user_id'";
$result = $db->query($query) or die(mysql_error());
$numhoefsmid = $db->num_rows($result);
$f = $db->fetch_array($result);
$tijd_ontslag = ($f[tijd] + 1209600);
$tijd = time();
if($tijd > $tijd_ontslag)
{
$query1 = "DELETE FROM instructie WHERE user='$user_id' LIMIT 1";
$result1 = $db->query($query1) or die(mysql_error());
$query2 = "DELETE FROM les_dress WHERE instructie='$user_id'";
$result2 = $db->query($query2) or die(mysql_error());
echo "<center>De baas was ontevreden met jou werk, hij heeft je daarom ontslagen!</center>";
include_once "../overig/opleiding.php";
exit();
}
$tijd_pen = rand(22982400,25401600);
$tijd_pensioen = ($f[tijd] + $tijd_pen);
if($tijd > $tijd_pensioen)
{
$query1 = "DELETE FROM instructie WHERE user='$user_id' LIMIT 1";
$result1 = $db->query($query1) or die(mysql_error());
$query2 = "DELETE FROM les_dress WHERE instructie='$user_id'";
$result2 = $db->query($query2) or die(mysql_error());
echo "<center>Je bent afgekeurd door de arbeidsinspectie!</center>";
include_once "../overig/opleiding.php";
exit();
}
?>
<form method="POST" action="<?php echo "$_SERVER[REQUEST_URI]"; ?>">
<?php
if($numhoefsmid == 0){
echo "Pagina alleen voor instructie.";
die();
}
if(isset($_POST[ja]))
{
}
else
{
?>
<center>
<?php
}
if(isset($_POST[ontslag]))
{
?>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="1">
<tr>
<th colspan=2>
Je kreeg nog een leuk afscheidsfeest, weet je zeker dat je weg wil?
</th>
</tr>
<tr>
<td>
<input type="submit" name="ja" value=" Ja, feest was een flop! ">
</td>
<td>
<input type="submit" name="nee" value=" Nee, het feestje was te leuk! ">
</td>
</tr>
</table>
<?php
}
if(isset($_POST[ja]))
{
$query3 = "DELETE FROM instructie WHERE user='$user_id' LIMIT 1";
$result3 = $db->query($query3) or die(mysql_error());
$meldingg = array
(
"Je baas vond het jammer dat je wegging!<br>",
"Met veel tranen heb jij je collega's verlaten!<br>"
);
$random_melding = array_rand($meldingg,1);
$melding1 = $meldingg[$random_melding];
echo "<center>".$melding1."</center>";
include_once "../overig/opleiding.php";
exit();
}
if(isset($_GET[actie]) AND isset($_GET[id]) AND is_numeric($_GET[id])){
$query88 = "SELECT * FROM les_dress WHERE id='$_GET[id]'";
$result88 = $db->query($query88) or die(mysql_error());
$numbekappen = $db->num_rows($result88);
if($numbekappen == 1){
$random = rand(1,3);
$rang = rand(2,4);
$tijd = time();
$rij = $db->fetch_array($result88);
$user = $rij[user];
$paard = $rij[paard];
$query8 = "SELECT * FROM paarden WHERE paard_id='$paard'";
$result8 = $db->query($query8) or die(mysql_error());
$row = $db->fetch_array($result8);
$paard_naam = addslashes($row[paard_naam]);
$rij_dress = $row[rij_dress];
$query8 = "SELECT * FROM gebruikers WHERE id='$user'";
$result8 = $db->query($query8) or die(mysql_error());
$row = $db->fetch_array($result8);
$eigenaar = addslashes($row[naam]);
$query8 = "SELECT * FROM gebruikers WHERE id='$user_id'";
$result8 = $db->query($query8) or die(mysql_error());
$row = $db->fetch_array($result8);
$hoefsmid = addslashes($row[naam]);
$kosten = rand(12,16);
$loon = $kosten;
$randdd = rand(8,10);
$tot = $randdd + $rij_dress;
if($tot > 100){
$tot = 100;
}
$tijd= time();
$query1 = "UPDATE instructie SET tot=tot+'1',tijd='$tijd' WHERE user='$user_id'";
$result1 = $db->query($query1) or die(mysql_error());
$query2 = "UPDATE gebruikers SET geld=geld+'$kosten',rang=rang+'1' WHERE id='$user_id'";
$result2 = $db->query($query2) or die(mysql_error());
$query3 = "UPDATE gebruikers SET geld=geld-'$kosten',rang=rang+'$rang' WHERE id='$user'";
$result3 = $db->query($query3) or die(mysql_error());
// les geven zelf
$query4 = "UPDATE paarden SET rij_dress='$tot',laatste_rij='$tijd',hoeven=hoeven-'0.5',verzorgings_punten=verzorgings_punten-'1' WHERE paard_id='$paard'";
$result4 = $db->query($query4) or die(mysql_error());
$query5 = "INSERT INTO afschriften (af_id,id,waarde,datum,van,naar,reden) values ('','$user','$kosten','$tijd','$eigenaar','$hoefsmid','Kosten rijles')";
$result5 = $db->query($query5) or die(mysql_error());
$query6 = "INSERT INTO berichten (id,van,naar,onderwerp,bericht,datum) VALUES ('','$hoefsmid','$eigenaar','Privé les','De dressuur les met $paard_naam is succesvol verlopen. De kosten waren € $kosten. Deze zijn automatisch van uw rekening afgeschreven.','$tijd')";
$result6 = $db->query($query6) or die(mysql_error());
$query7 = "DELETE FROM les_dress WHERE id='$_GET[id]'";
$result7 = $db->query($query7) or die(mysql_error());
echo "Les succesvol gegeven.<p>";
}
}
?>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="1" width="99%">
<tr><th colspan="2">Les geven</th></tr>
<tr><th>Gebruiker:</th><th>Les geven:</th></tr>
<?php
$query = "SELECT * FROM les_dress WHERE instructie='$user_id'";
$result = $db->query($query) or die(mysql_error());
$n = $db->num_rows($result);
if($n == 0)
{
echo "<tr><td colspan=3>Geen mensen willen instructie krijgen!</td></tr>";
}
else
{
while($row=$db->fetch_array($result)){
?>
<tr>
<td>
<?php
$query8 = "SELECT * FROM gebruikers WHERE id='$row[user]'";
$result8 = $db->query($query8) or die(mysql_error());
$lesser = $db->fetch_array($result8);
$eigenaar = $lesser[naam];
?>
<a href='../profiel/profiel_bekijken.php?naam=<?php echo "".urlencode($eigenaar).""; ?>&pp=../baantjes/les_geven2.php'><?php echo "$eigenaar"; ?></a>
</td>
<td>
<a href="?actie=les_geven&id=<?php echo $row[id]; ?>"><b>Les geven</b></a>
</td>
</tr>
<?php
}
}
?>
</table>
<p>
<?php
if(isset($_POST[pauze]))
{
$sqll = "SELECT * FROM instructie WHERE user='$user_id'";
$query = $db->query($sqll);
$f1 = $db->fetch_array($query);
if($f1[pauze] == 'Ja')
{
$sql2 ="UPDATE instructie SET pauze='Nee' WHERE user='$user_id'";
$db->query($sql2);
echo "<center>Je bent weer aan het werk!</center>";
}
else
{
$sql2 ="UPDATE instructie SET pauze='Ja' WHERE user='$user_id'";
$db->query($sql2);
echo "<center>Je bent nu aan het pauzeren!</center>";
}
}
?>
<p>
<table border="1" bordercolor="#000000" cellpadding="2" cellspacing="1">
<tr>
<th>
Opties
</th>
</tr>
<tr>
<td>
<input type="submit" name="ontslag" value=" Ik neem ontslag!* ">
</td>
</tr>
<tr>
<td>
<?php
if($f[pauze] == 'Ja')
{
?>
<input type="submit" name="pauze" value=" Ik ga weer aan het werk! ">
<?php
}
else
{
?>
<input type="submit" name="pauze" value=" Ik neem pauze! ">
<?php
}
?>
</td>
</tr>
<tr>
<td>
* = Je krijgt geen geld terug indien je ontslag neemt!
</td>
</tr>
</table>
</center>
</td>
<td width="150" align="center" valign="top">
<?php
include "../menu22.php";
?>
</td>
</tr>
</table>
<?php
include "../htmlbottom.php";
include "../close.php";
?>
1.816 views