PHP与MySQL的速度很慢 [英] PHP with MySQL is slow

查看:90
本文介绍了PHP与MySQL的速度很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(重要)单独运行testajax2.php,而不运行Ajax.持续时间大致相同,为1.02-1.03秒.所以我想这意味着问题出在PHP-MySQL或 XAMPP ??

(IMPORTANT) EDIT 3: Running the testajax2.php by itself and not Ajax. The duration is about the same, 1.02-1.03 seconds. So I guess that means the problem is in PHP-MySQL or XAMPP??

当我通过 phpMyAdmin 查询运行该查询时,结果如下:显示第0行- 29(总共约50.查询耗时 0.0015秒).看来问题根本不在于Ajax,而可能在于PHP.我怎样才能解决这个问题? (我也刚刚编辑了问题标题.)

When I ran it through a phpMyAdmin query, here's the result: Showing rows 0 - 29 ( ~50 total. The query took 0.0015 seconds). 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.)

答案:在C:\Windows\System32\drivers\etc

   127.0.0.1 localhost


之前的问题:

在另一侧使用SQL查询的最短持续时间为1秒的jQuery Ajax是否正常?我已经尝试过$.get$.post$.getjson$.ajax({type:'POST'})$.ajax({type:'GET'}).正如我所说的,这是最低要求.甚至可能恶化到大约3秒.我怀疑这是SQL查询,因为当我在phpMyAdmin中尝试它们时,结果显示得非常快.

Is it normal for jQuery Ajax with SQL queries on the other side have the minimum duration of 1 second? I've tried $.get, $.post,$.getjson,$.ajax({type:'POST'}), $.ajax({type:'GET'}). 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.

如果查询非常简单并且表中只有2个元素,也将紧随其后的是1秒的最小时间.我正在使用最新的XAMPP,我不知道这是否重要,但是我正在通过localhost和127.0.0.1访问文件.

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.

我正在本地环境中运行该文件,并在同一台笔记本电脑上运行这些文件. jQuery已更新.返回的值/数组是json_encoded.我正在使用mysqli.该数据库位于 InnoDB 中,并且其中只有大约五个表,几乎没有任何内容.他们.这是一个非常简单的示例查询:

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 five tables, and there are hardly anything on them. Here's a very simple sample query:

    var test_id =2;
    testcall();
    function testcall(){
        $.ajax({
            url: 'testajax2.php',
            type: 'POST',
            data: {test_id: test_id},
            success: function(data){

            }
        });
    }

文件testajax2.php

    $mysqli = new mysqli('localhost', 'root', '', 'testdb');
    $mysqli->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->query($query);
    $row = $result->fetch_all(MYSQLI_ASSOC);

    echo json_encode($row);

tblperson包含50条记录,并且只有四列.根据Firebug的说法,完成这个极其简单的任务需要1.03秒.我不确定它的真正含义,但可以通过

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 Net tab in Firebug, the bar is entirely violet. 0 and 1.03 seconds Waiting. +1.03 seconds and 0 receiving.

我以json_encode($row)foreach($row as $value){ echo $value['First_Name']; }的形式发送它们也没有关系.仍将至少大约1秒.我已经在Chrome和Safari上进行过尝试,尽管我没有确切的时间长度,但我可以说大致相同.但是对于一个简单的Ajax调用,它没有SQL查询.如果我没记错的话,它的速度非常快.我会返回一个示例和持续时间输出.

It also doesn't matter if I send them as json_encode($row) or foreach($row as $value){ echo $value['First_Name']; }. 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 no SQL queries. If I remember correctly, it's very fast. I'd be back with a sample and duration output.

推荐答案

在位于C:\Windows\System32\drivers\etc

   127.0.0.1 localhost

这解决了我的问题.现在,PHP-MySQL可以完成其任务,具体取决于20-500毫秒之间的复杂程度.

This solved my problem. PHP-MySQL can now complete its task depending on how complex somewhere between 20-500 ms.

这篇关于PHP与MySQL的速度很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆