使用 MySQL 的 PHP 很慢

PHP with MySQL is slow(使用 MySQL 的 PHP 很慢)
本文介绍了使用 MySQL 的 PHP 很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(重要)编辑 3: 单独运行 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:WindowsSystem32driversetc"的 hosts 文件中添加以下行

   127.0.0.1 localhost


之前的问题:

jQuery Ajax 是否正常,另一端的 SQL 查询具有 1 秒的最短持续时间?我试过 $.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){

            }
        });
    }

推荐答案

在位于"C:WindowsSystem32driversetc"的hosts文件中添加以下行

   127.0.0.1 localhost

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

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

这篇关于使用 MySQL 的 PHP 很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)