Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8967893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:20:48+00:00 2026-06-15T17:20:48+00:00

On my site I have coded a function that shows you how many unique

  • 0

On my site I have coded a function that shows you how many unique visitors and how many pageviews I get per day.

The problem is that sometimes the insert query takes forever and in InnoDB theres no DELAYED INSERT function.

Edit: It is using InnoDB, what I mean with long loading time is around 6 seconds instead of like 0.1-0.5 seconds. As soon as I remove the logging the site is much faster.

The $b array bellow contains browser info, but according to XHProf its the PDO query that’s taking so long to execute.

The insert code is this:

$values = array(
        'time' => time(),
        'ip' => $_SERVER['REMOTE_ADDR'],
        'page' => rtrim((isset($_GET['q']) ? $_GET['q'] : 'index'), '/'),
        'browser' => $b[11][0] . ' ' . $b[11][1],
        'os' => $uos,
        'referred' => (isset($_SERVER['HTTP_REFERER']) && !preg_match('|^' . Config::getValue('site', 'url') . '|', $_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''),
    );

    $this->table->insert($values);

and the insert function code:

public function insert($table, $data) {
    ksort($data);

    $fieldNames = implode('`, `', array_keys($data));
    $fieldValues = ':' . implode(', :', array_keys($data));

    $sth = $this->prepare('INSERT INTO ' . $table . '(`' . $fieldNames . '`) VALUES (' . $fieldValues . ');');

    foreach ($data as $key => $value) {
        $sth->bindValue(':' . $key, $value);
    }

    $sth->execute();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:20:49+00:00Added an answer on June 15, 2026 at 5:20 pm

    A minor optimization. The way you are doing your binding you can get rid of the foreach statement and pass the array directly to execute. PDO will map the arrays key to the :binding names you created in the prepare statement.

    $sth->execute($data);
    

    That said, you should look at your slow query log in mysql to see what is going on. Even though you are using Innodb, there are scenarios where Innodb will lock the table. That could be why inserts are taking a long time sometimes. You can reduce your slow query threshold to something like 3 seconds to capture the queries. The log will tell you how much time was spent in each stage (i.e. locked).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have create a site embedded Google mapusing api V3 that shows our 4
I have some code that sets the lang var to the site default language.
I have a large download site, an i have a code that updates each
I have a daily deal aggregator site and i can't get the Facebook share
I have a site that calls AJAX. It works at my office, where I
I have a site that plays a stream. I perform an AJAX call to
I have a problem using a small div that should hover over pics that
Here is my issue. I have an ASPX web site and I have code
I have a code for my site, when an image is clicked a pop
I have ace editor integrated in my site. I have some code there, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.