PHP - Super Slow Queries
Ok so I have a single mySQL database on a dedicated server hosted through hostgator..
In this database I have 1 table that is a very large table it has well over 900,000 rows on it and we anticipate another 8.1 million records to be added within another 6 months and from there expect the table to grow regularly. Right now my issue is and can only foresee it getting worse as the size gets larger. Is that my queries are running slower and slower. Sometimes even resulting in the DB crashing. So what I am trying to figure out is how do I speed this up. I've tried 101 ways to query the DB to speed it up and can't get it to load 10 results 10.. in less than 30 seconds. I know some of my issue is the fact that I need distinct results or unique ones rather. As there are several duplicate entries but I only need to pull out one of each for this particular function which is a search. So that said is there any advice one can give me to speed up my query results. I would offer up a sample of my current queries but its just your common query using distinct. Similar TutorialsHello again, I got a problem with one of my pages that uses MySql. I didn't expect my site to shoot up into the 1000's per hour but it has but has destroyed the loading time of one of my pages. Below is the function that is super slow! Code: [Select] function get_top($timeframe='today', $time=10, $friends=true, $limit=5, $unique=true, $me_only=false){ if($friends===false){$q='';}else{ $q=' AND (username IN ('; // This array can have upto 500 items in it. global $friend_id_array, $me;$tarray=$friend_id_array; $tarray[]=$me['id']; $x= implode(',',$tarray);$q.=$x; $q.= '))'; } if($me_only){ $q=' AND username = \''.$me['id'].'\' '; } if($timeframe=='today'){ $q_timeframe='AND DATE(thedate) = DATE(NOW()) AND YEAR(thedate) = YEAR(NOW())'; // Checking the date could be slow }else if($timeframe=='week'){ $q_timeframe='AND WEEK(thedate) = WEEK(NOW()) AND YEAR(thedate) = YEAR(NOW())'; }else if($timeframe=='month'){ $q_timeframe='AND MONTH(thedate) = MONTH(NOW()) AND YEAR(thedate) = YEAR(NOW())'; }else if($timeframe=='all'){ $q_timeframe=''; } if($unique){$q_unique='GROUP BY username';} $query="SELECT MAX(score) as highscore, username, timeframe, thedate FROM other_click WHERE (timeframe = '$time') $q $q_timeframe $q_unique ORDER BY highscore DESC LIMIT 0, $limit"; // A very long query $result=@mysql_query($query)or die(mysql_error()); if(@mysql_num_rows($result)>0){ while($row=@mysql_fetch_array($result)){ // Maybe resorting the array makes it super slow $id_array[]=$row; } return $id_array;}else{return false;} } I've commented the lines which I think maybe making this page load slowly. I also thought the way the page is loaded. The page is called 6 times per user but with different settings eg, Friends only and only scores added today. Please help because this is crippling my site. Thank-you all Paul I've got my own proprietary framework. I call it Brain. It uses composer, and installation is done with a single composer file, which is handy. Here's an example:
{ "name": "skunkbad/brain-test", "description": "My Awesome App", "license": "proprietary", "minimum-stability": "dev", "repositories": [ { "type": "hg", "url": "ssh://hg@bitbucket.org/skunkbad/brain" } ], "require": { "skunkbad/brain": "default" }, "scripts": { "post-install-cmd": "Brain\\Statics\\BrainInstallScript::run" } }Brain has it's own dependencies, which aren't all really dependencies, but I've added them all to its composer.json file so I get everything I want for a new project. Here is it's composer.json: { "name": "skunkbad/brain", "version": "1.0.0", "type": "framework", "license": "Proprietary", "authors": [ { "name": "Robert B Gottier", "email": "xXxXxXxXx@gmail.com", "homepage": "http://brianswebdesign.com", "role": "Developer" } ], "require": { "pimple/pimple" : "v2.0.0", "swiftmailer/swiftmailer": "v5.2.0", "dompdf/dompdf" : "0.6.1", "phpseclib/phpseclib" : "0.3.6", "stripe/stripe-php" : "v1.15.0", "firephp/firephp-core" : "dev-master", "doctrine/dbal" : "v2.4.2" }, "autoload": { "psr-4": { "Brain\\": "/", "App\\": "../../../App/" }, "classmap": [ "Statics/" ] } }In Windows terminal, I can run composer install or composer install --prefer-dist, and it seems that especially when the doctrine packages are being downloaded or cloned (whatever it does), its super slow. Some of them hang for so long that occasionally the terminal will give me a message indicating a particular package timed out (5 mins). So I was wondering if this is just the norm. Feels like I'm on dial-up, but my internet connection is Verizon FiOS (fiber optic). Here is an example of the time-out message I get from Composer: Failed to download doctrine/common from source: The process "git clone --no-checkout "git://github.com/doctrine/common.git" "C:\XXXxxx" && cd /D "C:\XXXxxx" && git remote add composer "git://github.com/doctrine/common.git" && git fetch composer" exceeded the timeout of 300 seconds. I timed my install, and composer/common actually hung for about 7 mins. Total time was 9.5 mins. would Java handle it faster? can PHP be made to handle it as fast? I really need help. check out my website and search cars for sale, then any distance and then 37919 zip. it takes too long and there are only 3351 cars on there now. before, when it only had about 2200 cars it was really fast. only about a 1000 cars made it slow. what could it be? nabacar.com It was returning results in about 15 seconds or less with 2200 cars. Now it is over a minute with only 1000 cars on it. I will have 150,000 on it when I get this sorted. http://nabacar.com some java was written to speed things up, but it didn't seem to help. Is it the server or the code causing this? Quote '31.100.x.x is not allowed to connect to this MySQL server in /home/member/insert.php on line 13 I asked a question about this a few weeks ago, and someone solved it saying that the server was blocking connections. Its confusing the hell out of me. I did as they said, and contacted my admin. they told me to fork over money, and it would be solved. I am a broke student, and dont have the cash anyway. What gets me is they said I had to be a paid member to have a sql database and connect to it with scripts on the server. But I can run a phpBB3 forum. it runs sql. I know it does. WTF? I know they are just trying to get money from me, but no matter how much I try i cant figure out how the forums connect. mine is Code: [Select] $username="a162_bento"; $password="Password123"; $database="a162_siteDB"; $localhost="host.com"; mysql_connect($localhost,$user,$password) I wish could figure out how xampp worked. If someone has time to help me I would really appreciate it. Im trying really hard but getting kick every time i get on the stage. Hi I'm currently experiencing problems with my super global outputs.
I'm using
$_SERVER['HTTP_X_MXIT_NICK']; Using: $file = fopen("file1.txt", "r") or exit("Unable to open file!"); I have multiple files (file1.txt, file2.txt, etc.) how can I edit this so it just takes ANY file that ends in .txt and opens it? Hi guys, I am trying out this code but it does not work, any idea what I am doing wrong? <?php include 'connect.php'; $tbl_name="users"; $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF">#</td> <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Firstname</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Location</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Website</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> <td bgcolor="#FFFFFF"><? echo $rows['userID']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['firstname']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['location']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['website']; ?></td> </tr> <?php } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <? if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql); } if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=showusers2.php\">"; } } mysql_close(); ?> </table> </form> </td> </tr> </table> Hey all, I'm well aware of associative arrays (key/value pairs) and how you can index them in an array like this: $character = array (name=>"John", occupation=>"Programmer", age=>22, "Learned language "=>"PHP" ); Then it makes sense to iterate through the key/value pairs of the array using foreach: foreach ( $character as $key=>$val ){ print "$key = $val<br>"; } However, I was watching a video tutorial where he created a $_SESSION array and then created an array associative array: $_SESSION['cart'] = array(); [/PHP] Then he added a function add_to_cart: function add_to_cart($id){ if(isset($_SESSION['cart'][$id])){ $_SESSION['cart'][$id]++; return true; } else { $_SESSION['cart'][$id] = 1; return true; } return false; } Now that $id variable holds an id converted to integer from the dataabse. So if first item is clicked, id holds a value of integer 1. When I see this: $_SESSION['cart'][$id] I see an array that holds two indexes, each index containing an associative array: [[array() => ''], [1 => '']]. So at index 0 of $_SESSION is [array() => '']. But then he uses the foreach iterator like this: function total_items($cart){ $items = 0; if(is_array($cart)){ foreach($cart as $id => $qty){ $items += $qty; d } } return $items; } Now I'm very confused. As you can see in that foreach method, it says that $id (and its corresponding value) is an associative array of $cart array, not $_SESSION array. I don't see how that happened. I thought $cart and id$ were distinct indexes of $_SESSION. I don't see how $id is a key of the $cart array. Thanks for any explanation to clear my confusion. I am aiming to use setcookie to refresh the expiry of a cookie on EVERY page request. Is this slow? I'm sure I can design things so i don't need to reset it on every page request, but if it isn't a big deal then I'll do it. Is setcookie slow? Ok, so basically someone submits a file (doc) and I need to see if it is the same as another file. So instead of opening 300+ files and checking for word similarity, I put the file info into a table called newnotes. Then check the file size for each of the notes in "newnotes" against all of the notes in the table "approvednotes" this could be something like matching 20 file sizes to 300+ file sizes. The user gets returned back to a page and this is all done in backend by the click of a button the admins can use. But would doing this slow down my server/website? I have swift mailer setup to send two message and plain and HTML. I have followed a lot of different posts and came up with a solution that works. However when I send for example 7k emails only about 500 made it out before the 30sec timeout. So I switched my timeout to 600secs and only about 3k made it out. I now I can switch my timeout to 0 or 3600sec and it will go through but it doesnt seem like this should take so long. I use Debian 6.0, Zimbra 7, Postfix, and SwiftMailer I am using the mailer like this; / Create the Transport $transport = Swift_SmtpTransport::newInstance('localhost', xx) ->setUsername('xxx') ->setPassword('xxx') ; // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); //Starts the loop to separate the to email addresses everything past here is built for each email $to1 = explode(", ", $to); for($i = 0; $i < count($to1); $i++){ // Create a message $message = Swift_Message::newInstance($subject) ->setFrom(array($from => 'xxx')) ->setTo(array($to1[$i])) ->setBody($plaintxt) ->addPart($htmltxt, 'text/html'); $plaintxt = substr($plaintxt, 0, -$plaindumplength); $htmltxt = substr($htmltxt, 0, -$dumplength); $emailcounter += $mailer->send($message); } Hi, I am having a problem with a part of my query: "SELECT SQL_CALC_FOUND_ROWS jobs.id AS jobId, enquiries.id AS profId, users.username, entity_details.name AS entityName, branches.name AS branch, orderNumber, entity_vat_numbers.vatCode, entity_account_numbers.accountNumber, (SELECT symbol FROM parts_trading, currencies WHERE parts_trading.enquiryRef = enquiries.id AND parts_trading.sellingCurrency = currencies.id LIMIT 1) AS symbol, (SELECT SUM(quantity) FROM parts_trading WHERE enquiryRef = enquiries.id) - COALESCE((SELECT SUM(quantity) FROM invoices_out_reference WHERE jobRef = jobs.id), 0) AS differentPartsCount, (SELECT SUM(quantity*sellingNet) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) - COALESCE( (SELECT SUM(invoices_out.net) FROM invoices_out, invoices_out_reference WHERE invoices_out_reference.invoiceRef = invoices_out.id AND invoices_out_reference.jobRef = jobs.id ) , 0) AS netRemaining, (SELECT SUM(quantity*sellingVat) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) - COALESCE( (SELECT SUM(invoices_out.vat) FROM invoices_out, invoices_out_reference WHERE invoices_out_reference.invoiceRef = invoices_out.id AND invoices_out_reference.jobRef = jobs.id ) , 0) AS vatRemaining, (SELECT SUM(quantity*(sellingNet+sellingVat)) FROM parts_trading WHERE parts_trading.enquiryRef = enquiries.id) - COALESCE( (SELECT SUM(invoices_out.net+invoices_out.vat) FROM invoices_out, invoices_out_reference WHERE invoices_out_reference.invoiceRef = invoices_out.id AND invoices_out_reference.jobRef = jobs.id ) , 0) AS totalRemaining FROM jobs, enquiries, users, branches, entity_details LEFT JOIN entity_account_numbers ON entity_details.id = entity_account_numbers.entityRef LEFT JOIN entity_vat_numbers ON entity_details.id = entity_vat_numbers.entityRef WHERE enquiries.traderRef = users.id AND jobs.enquiryRef = enquiries.id AND users.branchRef = branches.id AND (SELECT SUM(quantity) FROM parts_trading WHERE enquiryRef = enquiries.id) - COALESCE((SELECT SUM(quantity) FROM invoices_out_reference WHERE jobRef = jobs.id), 0) > 0 AND enquiries.entityRef = entity_details.id" I know for certain that it is the part: "AND (SELECT SUM(quantity) FROM parts_trading WHERE enquiryRef = enquiries.id) - COALESCE((SELECT SUM(quantity) FROM invoices_out_reference WHERE jobRef = jobs.id), 0) > 0" That is causing the problem. Unfortunately this is a vital part of my query used for not displaying rows that have quantities matching the sum of what is in the other table . Is there are more efficient way to get the same result than that part of the query? hey i have a problem when i try to send email through php it seems to take a long time somethings it can be there quickly but somethings it takes forever is it something im doing wrong in the short script this is part of my script Code: [Select] // email profile owner $webmaster = "admin@website.com"; $headers = "From: mywebsite<$webmaster>"; $subject = "$username has commented on your profile"; $message = "Hello $firstname $lastname. $username has posted a comment on your profile on mywebsite.com"; $message .= " The message $username has posted with is below.\n"; $message .= "\n****************************************************************\n"; $message .= "$comment"; $message .= "\n\n****************************************************************\n\n"; $message .= "Click here to view $username's profile $site/profile?id=$userid\n"; $message .= "Click here to view your profile $site/profile?id=$getid\n"; // send email mail($email, $subject, $message, $headers); Hi, I coded this website in php http://www.3gar.info but it seem very slow. I checked the server but they said everything is ok and the website run smoothly in server. I have another copy of this website in hostmonister it run very fast there. http://www.ibuj.org Let's say I have a forum with 300 active people posting 24/7 I have error reporting turned off. But if I turn it on, it shows 100-200 Undefined variable's error's on each forum page, even if it's off does it effect performance or does it matter if the php is writing to a error_log? If so how can I disable php writing to a error_log as I have no sense or no need for it. Thanks, and would the speed be noticable if I went ahead and fixed all the errors, if it would help? or no I code fine, it's just i dont use the isset.. I have the following simple code to test against collision on a primary key I am creating: Code: [Select] $machine_ids = array(); for($i = 0; $i < 100000; $i++) { //Generate machine id returns a 15 character alphanumeric string $mid = Functions::generate_machine_id(); if(in_array($mid, $machine_ids)) { die("Collision!"); } else { $machine_ids[] = $mid; } } die("Success!"); Any idea why this is taking minutes to run? Anyway to speed it up? Hi Guys We have had a holiday program written in php in the past by an experienced developer but we are experiencing problems now. So I am curious to try and resolve the best approach Here goes 1: We query multiple APIs to return holiday results to our users 2: This can take up to 20 seconds to return results but sometimes its much quicker depending on the volume of API returned results 3: Other users seem to be locked out of even visiting our website if an API call is running So initially without posting any code, I have a couple of questions which are A: Is there a way to maybe poll a process or allow partial results to the users browser while things run in the background ( similar to what other holiday providers seem to be doing ) B: Is there a way to speed this up or maybe some sort of better technology to utilise
Many thanks professionals Hi everyone, I have a data analysis system which, however, takes too long to insert data into the db. Can you help me understand where I went wrong? thank you DB MYSQL:
1 analytics_number bigint(20) AUTO_INCREMENT --------------------------------------------------------------------------- CLASS PHP Analytics.php class analytics {
public $search_sites; public function get_analytics_enter($visitor_ip, $visitor_visitor_id, $visitor_session_id, $visitor_pageview_id, $visitor_referrer, $visitor_url, $visitor_resolution, $visitor_viewport, $visitor_document){ try{
$GET_array = array("visitor_ip" => $visitor_ip, "visitor_visitor_id" => $visitor_visitor_id, "visitor_session_id" => $visitor_session_id, "visitor_pageview_id" => $visitor_pageview_id, "visitor_referrer" => $visitor_referrer, "visitor_url" => $visitor_url, "visitor_resolution" => $visitor_resolution, "visitor_viewport" => $visitor_viewport, "visitor_document" => $visitor_document);
$query = "SELECT * FROM analytics WHERE visitor_visitor_id = '".$visitor_visitor_id."'"; $visitor_ip_info = get_data_visitor($visitor_ip);
$visitor_visitor_pageview = 0;
$session_buffer = array();
$visitor_visitor_pages = array();
$analytics["visitor_session_landingpage"] = NULL;
foreach ($visitor_data as $visitor) {
if (!in_array($visitor["visitor_page_path"], $visitor_visitor_pages)) {
if ($visitor["visitor_session_id"] == $visitor_session_id) {
if ($visitor_session_pageview == 1) {
if (!in_array($visitor["visitor_page_path"],$visitor_session_pages)) {
if (!in_array($visitor["visitor_session_id"],$session_buffer)) {
if (!in_array($visitor_session_id,$session_buffer)) {
foreach($GET_array as $key => $value) {
$analytics["visitor_visitor_sessions"] = $visitor_visitor_session;
$analytics["visitor_visitor_pageviews"] = $visitor_visitor_pageview + 1; $analytics["visitor_visitor_time"] = "0";
$analytics["visitor_session_pageviews"] = $visitor_session_pageview + 1;
$analytics["visitor_enter_timestamp"] = date("d.m.Y, H:i:s");
$analytics["visitor_leave_timestamp"] = date("d.m.Y, H:i:s"); $analytics["visitor_pageview_time"] = "0";
$analytics["visitor_country"] = $visitor_ip_info["country"];
$analytics["visitor_referrer_url"] = $visitor_referrer;
$analytics["visitor_domain"] = $this->get_domain($visitor_url);
if (!in_array($analytics["visitor_page_path"], $visitor_visitor_pages)) {
if (!in_array($analytics["visitor_page_path"], $visitor_session_pages)) {
$analytics["visitor_visitor_pages"] = json_encode($visitor_visitor_pages);
if ($analytics["visitor_session_pageview"] == 1) {
$sql_1_1 = "UPDATE analytics SET " . "visitor_visitor_last_page" . "='" . "" . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'";
$sql_1 = $sql_1_1."; ".$sql_1_2.";";
$analytics["visitor_visitor_last_page"] = "true";
$analytics["visitor_device"] = visitor_device(); $analytics["visitor_pageview_update"] = date("YmdHis");
$sql_2_1 = "INSERT INTO analytics ("; $this->_db->exec($sql_2_1); $sql_2_2 = "UPDATE analytics SET " . "visitor_visitor_sessions" . "='" . $analytics["visitor_visitor_sessions"] . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'"; $sql_2_3 = "UPDATE analytics SET " . "visitor_visitor_pageviews" . "='" . $analytics["visitor_visitor_pageviews"] . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'"; $sql_2_4 = "UPDATE analytics SET " . "visitor_visitor_pages" . "='" . $analytics["visitor_visitor_pages"] . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'"; $sql_2_5 = "UPDATE analytics SET " . "visitor_session_pageviews" . "='" . $analytics["visitor_session_pageviews"] . "' WHERE " . "visitor_session_id" . "='" . $visitor_session_id."'"; $sql_2_6 = "UPDATE analytics SET " . "visitor_session_pages" . "='" . $analytics["visitor_session_pages"] . "' WHERE " . "visitor_session_id" . "='" . $visitor_session_id."'"; $sql_2_7 = "UPDATE analytics SET " . "visitor_session_landingpage" . "='" . $analytics["visitor_session_landingpage"] . "' WHERE " . "visitor_session_id" . "='" . $visitor_session_id."'"; $sql_2_8 = "UPDATE analytics SET " . "visitor_session_exitpage" . "='" . $analytics["visitor_session_exitpage"] . "' WHERE " . "visitor_session_id" . "='" . $visitor_session_id."'";
$sql_2 = $sql_2_2.";".$sql_2_3.";".$sql_2_4.";".$sql_2_5.";".$sql_2_6.";".$sql_2_7.";".$sql_2_8.";";
} catch(PDOException $e) { public function get_analytics_update($visitor_visitor_id, $visitor_session_id, $visitor_pageview_id, $visitor_pageview_time, $visitor_leave_url){
try{ $query = "SELECT MAX(" . "visitor_session_time" . ") FROM analytics WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "' AND " . "visitor_session_id" . "='" . $visitor_session_id . "' ORDER BY " . "visitor_enter_id" . " DESC LIMIT 1"; $visitor_session_time = $this->_db->query($query)->fetchColumn();
$query = "SELECT MAX(" . "visitor_pageview_time" . ") FROM analytics WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "' AND " . "visitor_session_id" . "='" . $visitor_session_id . "' AND " . "visitor_pageview_id" . "='" . $visitor_pageview_id . "' ORDER BY " . "visitor_enter_id" . " DESC LIMIT 1"; $analytics = array();
foreach($GET_array as $key => $value) {
$analytics["visitor_leave_timestamp"] = date("d.m.Y, H:i:s");
$analytics["visitor_visitor_time"] = $visitor_visitor_time + ($visitor_pageview_time - $visitor_pageview_time); $analytics["visitor_pageview_update"] = date("YmdHis");
if (isset($visitor_leave_url)) {
$sql_1_1 = "UPDATE analytics SET ";
} catch(PDOException $e) {
function visitor_referrer_type($referrer) {
if ($referrer == "") {
$referrer = explode(".",$referrer);
if (array_key_exists($referrer,$search_sites)) {
function visitor_referrer_name($referrer) {
if ($referrer == "") {
$referrer = explode(".",$referrer);
if (array_key_exists($referrer,$search_sites)) {
function visitor_leave_type($leave_url)
if ($leave_url == "") {
if (strpos($leave_url, $url_paz) !== false) {
function visitor_leave_name($leave_url) $leave_url = $this->get_domain($leave_url);
$leave_url = explode(".",$leave_url); } ?> analytics-db.php
<?php // Dataset IDs
array_push($database_structure["analytics"],"visitor_visitor_id"); // Dataset Visitor Data
array_push($database_structure["analytics"],"visitor_visitor_sessions"); // Dataset Session Data
array_push($database_structure["analytics"],"visitor_session_pageviews"); // Dataset Pageview Data // Dataset Enter Time
array_push($database_structure["analytics"],"visitor_enter_timestamp"); // Dataset Leave Time
array_push($database_structure["analytics"],"visitor_leave_timestamp"); // Dataset Geolocation
array_push($database_structure["analytics"],"visitor_country"); // Dataset Technology
array_push($database_structure["analytics"],"visitor_device"); // Dataset Referrer
array_push($database_structure["analytics"],"visitor_referrer_url"); // Dataset Page
array_push($database_structure["analytics"],"visitor_url"); // Dataset Time array_push($database_structure["analytics"],"visitor_pageview_time"); // Dataset Leave
array_push($database_structure["analytics"],"visitor_leave_url"); // Dataset Update
array_push($database_structure["analytics"],"visitor_pageview_update"); analytics-enter.php <?php
if(isset($_POST["visitor_ip"])){ ?> analytics-update.php <?php $analytics->get_analytics_update($_POST["visitor_visitor_id"], $_POST["visitor_session_id"], $_POST["visitor_pageview_id"], $_POST["visitor_pageview_time"], $_POST["visitor_leave_url"]); ?> JS FILE $(function(){
function create_cookie(name,value,days) {
var host = window.location.hostname;
document.cookie = name+"="+value+expires+"; path=/; domain=." + domain;
function read_cookie(name) {
while (c.charAt(0) == ' ') {
if (c.indexOf(nameEQ) == 0) {
function random_string(length, chars) {
function create_id() {
function create_visitor_visitor_id() {
function visitor_visitor_id() {
function create_visitor_session_id() {
function visitor_session_id() {
if (new URL(window.location.href).searchParams.get("analytics") != "true") { var analytics_script_location = "/analytics/controllers/";
var screen_width = screen.width;
var viewport_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var document_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var visitor_ip;
var visitor_visitor_id = visitor_visitor_id();
var visitor_enter_time = new Date();
var visitor_resolution = screen_width + "x" + screen_height; var visitor_leave_url = "NULL"; var current_time = 0;
var scroll_sum = 0;
var visitor_enter_sent = false;
var current_viewport_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var current_viewport = current_viewport_width + "x" + current_viewport_height;
var current_document = current_document_width + "x" + current_document_height;
function track_a_href(event) {
function analytics_visitor_enter() {
$.ajax({
function analytics_visitor_update() {
$.ajax({
window.setInterval(function() {
function analytics_visitor_leave() {
function visitor_leave_delay(time) {
$(window).load(function() { analytics_visitor_enter(); }); } }); Hello, I'm using php's mail function to send sms messages to my sprint phone. Sometimes I receive the text right away and other times it comes in as much as an hour or so later. My server is on GoDaddy. Does anyone have any ideas about what could be causing the bottleneck? To debug this I tried sending sms messages from my comcast email. So far those are always received very quickly. Perhaps the issue is on the GoDaddy server... I might try contacting them. By the way, it seems like the first text I send is received quickly, but then if I send other text messages within some short time frame, those don't always show up immediately. Has anyone else experienced anything similar? hi, when I made my website I thought it would be a good idea to put the information I'm outputting in a function so I could just call that function on a single template page. However, everytime I load a page on the server it loads all the static content first (ie, sidebar, logo, ect.) Then it loads the dynamic content. I'm okay with this, but it also doesn't add in the background until after it loads the dynamic content (which bothers me). Can I re-arrange my site's coding to prevent this? Thanks - charlie PS: my site is www.rushhunt.com |