Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP with MySQL is Slow
    primarykey
    data
    text
    <p><strong>(IMPORTANT) EDIT 3:</strong> Running the testajax2.php by itself and NOT AJAX. The duration is about the same, 1.02-1.03s. So I guess that means the problem is in PHP-MYSQL or XAMPP?? When ran through phpmyadmin query, here's the result: Showing rows 0 - 29 ( ~50 total , Query took <strong>0.0015 sec</strong>). It appears the problem lies not in Ajax after all, but perhaps in PHP. Help please... (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> <p><hr><hr> <em>The question before:</em> Is it normal for Jquery Ajax with sql queries on the other side have the <strong>minimum duration of 1 sec</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 sec 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. Thanks!</p> <p>EDIT: Thanks for the reply, guys. 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 InnoDB, and within are only about 5 tables, and there are hardly anything on them. Here's a very simple sample query:<br></p> <p><strong>index.php</strong></p> <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> <p><strong>testajax2.php</strong></p> <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 4 columns. According to Firebug, it took 1.03s to do that extremely simple task. I'm not sure what it really means, but viewing through Net tab in Firebug, the bar is entirely violet. 0 and 1.03s Waiting. +1.03s and 0 Receiving.</p> <p>EDIT 2: 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 sec. 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 simple ajax call with NO SQL QUERIES. If I remember correctly, it's very fast. I'd be back with a sample and duration output.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload