title: PHP with MySQL is slow
body: <p><strong>(IMPORTANT) EDIT 3:</strong> Running the testajax2.php by itself and <em>not</em> Ajax. The duration is about the same, 1.02-1.03 seconds. So I guess that means the problem is in PHP-MySQL or <a href="http://en.wikipedia.org/wiki/XAMPP" rel="nofollow noreferrer">XAMPP</a>??</p>
  
  <p>When I ran it through a <a href="http://en.wikipedia.org/wiki/PhpMyAdmin" rel="nofollow noreferrer">phpMyAdmin</a> query, here's the result: Showing rows 0 - 29 ( ~50 total. The query took <strong>0.0015 seconds</strong>). It appears the problem lies not in Ajax after all, but perhaps in PHP. How can I fix this? (I've also just edited the question title.)</p>
  
  <p><strong>Answer:</strong> Add the following line in the hosts file located in <code>”C:\Windows\System32\drivers\etc”</code></p>
  
  <pre><code>   127.0.0.1 localhost
  </code></pre>
  
  <hr/>
  
  <p><em>The question before:</em></p>
  
  <p>Is it  normal for jQuery Ajax with SQL queries on the other side have the <strong>minimum duration of 1 second</strong>? I've tried <code>$.get</code>, <code>$.post</code>,<code>$.getjson</code>,<code>$.ajax({type:'POST'})</code>, <code>$.ajax({type:'GET'})</code>. As I've said, it's the minimum. It could get worse to about 3 seconds even. I doubt it's the SQL queries though, as when I try them in phpMyAdmin, the results come up extremely fast.</p>
  
  <p>It doesn't matter also if the queries are very simple and the table only has 2 elements, it would still follow the 1 sec minimum. I'm using the latest XAMPP, and I don't know if it matters, but I'm accessing the files through localhost and 127.0.0.1.</p>
  
  <p>I'm running it on a local environment, on the same laptop I made these files on. jQuery is updated. The returned value/array is json_encoded. I'm using mysqli. The database is in <a href="http://en.wikipedia.org/wiki/InnoDB" rel="nofollow noreferrer">InnoDB</a>, and within are only about five tables, and there are hardly anything on them. Here's a very simple sample query:<br></p>
  
  <h3>File <code>index.php</code></h3>
  
  <pre><code>    var test_id =2;
      testcall();
      function testcall(){
          $.ajax({
              url: 'testajax2.php',
              type: 'POST',
              data: {test_id: test_id},
              success: function(data){
  
              }
          });
      }
  </code></pre>
  
  <h3>File <code>testajax2.php</code></h3>
  
  <pre><code>    $mysqli = new mysqli('localhost', 'root', '', 'testdb');
      $mysqli-&gt;set_charset("utf8");
      if(mysqli_connect_errno()) {
          echo "Connection Failed: " . mysqli_connect_errno();
          exit();
      }
  
      $testreceive = $_POST['test_id'];
      $query = "SELECT First_Name from tblperson";
      $result = $mysqli-&gt;query($query);
      $row = $result-&gt;fetch_all(MYSQLI_ASSOC);
  
      echo json_encode($row);
  </code></pre>
  
  <p>The tblperson contains 50 records, and there are only four columns. According to Firebug, it took 1.03 seconds to do that extremely simple task. I'm not sure what it really means, but viewing through the <em>Net</em> tab in <a href="http://en.wikipedia.org/wiki/Firebug_%28software%29" rel="nofollow noreferrer">Firebug</a>, the bar is entirely violet. 0 and 1.03 seconds Waiting. +1.03 seconds and 0 receiving.</p>
  
  <p>It also doesn't matter if I send them as <code>json_encode($row)</code> or <code>foreach($row as $value){ echo $value['First_Name']; }</code>. It would still be about at least 1 second. I've tried on Chrome and Safari, and though I can't have the exact duration, I can tell that it's about the same. But for a simple Ajax call with <em>no SQL queries</em>. If I remember correctly, it's very fast. I'd be back with a sample and duration output.</p>