You are here: Re: Timer « PHP Programming Language « IT news, forums, messages
Re: Timer

Posted by scuniverse@gmail.com on 05/29/06 19:11

Here is part of the code, it's a little long though

<?php
//Timer
function getmicrotime()
{
list($usec, $sec) = explode(" ", microtime());
return((float)$usec + (float)$sec);
}
$time_start = getmicrotime();

function totaltime($time_start)
{
$time_end = getmicrotime();
return(round(($time_end - $time_start), 6));
}

//Code
include_once("../inc/config.php");
error_reporting (E_ERROR);

dbConnect("sessions");
$sqlUID = "SELECT ID, Race, Min, Gaz, Size FROM user";
$UsersID = mysql_query($sqlUID) or die("Query failed");

$i = 1;
while ($UserID = mysql_fetch_array($UsersID)) {
$UrsID = $UserID['ID'];

// Terran
if ($UserID['Race'] == 'Terran') {
$sqlOBu = "SELECT * FROM units WHERE ID = '$UrsID'";
$UserOnB = mysql_query($sqlOBu) or die("Query B failed");
$UserONBU = mysql_fetch_array($UserOnB);

$sqlBU = "SELECT * FROM build WHERE ID = '$UrsID'";
$UserB = mysql_query($sqlBU) or die("Query B failed");
$UserBU = mysql_fetch_array($UserB);

//units build on the barracks
$FACB = $UserONBU[4] + $UserONBU[6] + $UserONBU[8] +
$UserONBU[10];
//units build on the factory
$FACF = $UserONBU[12] + $UserONBU[14] + $UserONBU[16];
//Buildings built by the SCV
$FACSCV = $UserBU[2] + $UserBU[4] + $UserBU[6] + $UserBU[8] +
$UserBU[10] + $UserBU[12] + $UserBU[14] + $UserBU[16] + $UserBU[18] +
$UserBU[20];

//SCV per tick
$SCVPT = $UserBU[1] * 5;
//Total SCV built this tick
$SCVTA = $UserONBU[2] - $SCVPT;
//same as for SCV only for the rest of the units
$MarPT = $UserBU[9] * 4.2 * ($UserONBU[6] / $FACB);
$MarTA = $UserONBU[6] - $MarPT;
$FirPT = $UserBU[9] * 4.2 * ($UserONBU[8] / $FACB);
$FirTA = $UserONBU[8] - $FirPT;
$GhoPT = $UserBU[9] * 2 * ($UserONBU[10] / $FACB);
$GhoTA = $UserONBU[10] - $GhoPT;
$VulPT = $UserBU[17] * 3.3 * ($UserONBU[12] / $FACF);
$VulTA = $UserONBU[12] - $VulPT;
$GolPT = $UserBU[17] * 2.5 * ($UserONBU[14] / $FACF);
$GolTA = $UserONBU[14] - $GolPT;
$TanPT = $UserBU[17] * 2 * ($UserONBU[16] / $FACF);
$TanTA = $UserONBU[16] - $TanPT;


//Total SCVs and remaining SCVs to be built
if ($SCVTA < 0 or $SCVTA == 0) {
$SCVTAD = $UserONBU[2] + $UserONBU[1];
$SCVOB = 0;
} else {
$SCVTAD = $SCVPT + $UserONBU[1];
$SCVOB = $SCVTA;
}
if ($MarTA < 0 or $MarTA == 0) {
$MarTAD = $UserONBU[6] + $UserONBU[5];
$MarOB = 0;
} else {
$MarTAD = $MarPT + $UserONBU[5];
$MarOB = $MarTA;
}
if ($FirTA < 0 or $FirTA == 0) {
$FirTAD = $UserONBU[8] + $UserONBU[7];
$FirOB = 0;
} else {
$FirTAD = $FirPT + $UserONBU[7];
$FirOB = $FirTA;
}
if ($GhoTA < 0 or $GhoTA == 0) {
$GhoTAD = $UserONBU[10] + $UserONBU[9];
$GhoOB = 0;
} else {
$GhoTAD = $GhoPT + $UserONBU[9];
$GhoOB = $GhoTA;
}
if ($MedTA < 0 or $MedTA == 0) {
$MedTAD = $UserONBU[3] + $UserONBU[4];
$MedOB = 0;
} else {
$MedTAD = $MedPT + $UserONBU[3];
$MedOB = $MedTA;
}
if ($VulTA < 0 or $VulTA == 0) {
$VulTAD = $UserONBU[11] + $UserONBU[12];
$VulOB = 0;
} else {
$VulTAD = $VulPT + $UserONBU[11];
$VulOB = $VulTA;
}
if ($GolTA < 0 or $GolTA == 0) {
$GolTAD = $UserONBU[13] + $UserONBU[14];
$GolOB = 0;
} else {
$GolTAD = $GolPT + $UserONBU[13];
$GolOB = $GolTA;
}
if ($TanTA < 0 or $TanTA == 0) {
$TanTAD = $UserONBU[15] + $UserONBU[16];
$TanOB = 0;
} else {
$TanTAD = $TanPT + $UserONBU[15];
$TanOB = $TanTA;
}


//Total strenght
$Nstrenght = ($UserID['Size'] / 2) + ($UserBU[1] * 2 +
$UserBU[3] + $UserBU[5] + $UserBU[7] + $UserBU[9] + $UserBU[11] +
$UserBU[13] + $UserBU[15]) + $UserBU[17] + $UserBU[19] + ($UserONBU[1]
* 2 + $UserONBU[3] + $UserONBU[5] + $UserONBU[7] + $UserONBU[9] +
$UserONBU[11] + $UserONBU[13] + $UserONBU[15]);

//calcul of the SCV and command center effect on minerals and
gaz gathering
$LCC = log10(($UserBU[1] / $UserID['Size']) * 10 + 1);
$LSC = log(($UserONBU[1] / $UserID['Size']) + 1, 2);
$Fac = $LCC * $LSC * $UserID['Size'] * 100;

$NMin = (int)($Fac + $UserID[1]);
$NGz = (int)(($Fac / 3) + $UserID[2]);

//Automatic increase of land... for now.
$NSize = ($UserID['Size'] * 0.01 + 1) + $UserID['Size'];

$UpdateOB = mysql_query("UPDATE units SET
SCVEd='$SCVTAD',SCVIng='$SCVOB',MarEd='$MarTAD',MarIng='$MarOB',FireEd='$FirTAD',FireIng='$FirOB'
,GhostEd='$GhoTAD',GhostIng='$GhoOB',MedEd='$MedTAD',MedIng='$MedOB',VulEd='$VulTAD',VulIng='$VulOB',GolEd='$GolTAD',GolIng='$GolOB'
,TankEd='$TanTAD',TankIng='$TanOB' WHERE ID='$UrsID'") or
die(mysql_error());

$UpdateBU = mysql_query("UPDATE build SET
CCB='$CCoTAD',CCOB='$CCoOB',SDB='$DepTAD',SDOB='$DepOB',RefB='$RefTAD',RefOB='$RefOB',BarrB='$BarTAD',BarrOB='$BarOB'
,FacB='$FacTAD',FacOB='$FacOB',EBB='$BayTAD',EBOB='$BayOB',AcaB='$AcaTAD',AcaOB='$AcaOB',ArmB='$ArmTAD',ArmOB='$ArmOB',SFB='$SciTAD',SFOB='$SciOB'
,BunkB='$BunTAD',BunkOB='$BunOB' WHERE ID='$UrsID'") or
die(mysql_error());

$UpdateMG = mysql_query("UPDATE user SET
Min='$NMin',Gaz='$NGz',NW='$Nstrenght',Size='$NSize' WHERE
ID='$UrsID'") or die(showError('3', mysql_error()));
}



I've cut a part on the code but its basically the same thing only for
the building where here its just for the units and there's 2 more
cases afterwards for 2 other races, the division by zero errors I get
them after "//SCV per tick" and every time I divide something by
$FACB, this variable is usually not 0, its 0 now cause I'm still
testing this, that said I could put a condition there cause there's
no point to do that part when $FACB = 0 or $FACF =0.

Is it possible that the server slows down the speed of the script for
some reason ? seems to me that there's a link between the error
messages and the time it takes to run the script, and this only happens
with the web cron service and not when I request the url with a browser.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация