I
I
Igor Samokhin2013-06-13 13:24:51
PHP
Igor Samokhin, 2013-06-13 13:24:51

Why is the same serial query running slower?

Good afternoon everyone,

On one project (without CMS) I noticed that the same action (for example, deleting a post with an ajax request) is slower every time.

That is, on the page I clicked "delete" - an ajax request went, returned after 80ms. I scroll down - I press delete - the post request has already returned after 3s and so on ... The next one will return after 8 seconds

I have no idea where to dig? Maybe the host has something?

Answer the question

In order to leave comments, you need to log in

7 answer(s)
N
Nikolai Vasilchuk, 2013-06-13
@Anonym

Sorry of course, but with such code - it is not surprising.

E
Egor, 2013-06-13
@ese

Is the response from the request to the browser returned with a delay or in a JS callback? If in the browser, then first of all, log everything related to this request on the server (execution time in the database, processing time, etc.). It will become clear in which direction to dig.

M
Max, 2013-06-13
@7workers

Where is it slowing down? Have you looked at the network tab in chrome's developer tools?

L
lightsgoout, 2013-06-13
@lightsgoout

Well, you need to profile the code, you can use xdebug, or you can just stick $time_start = microtime(true); <кусок кода> $time_end = microtime(true) - $time_start;it in and see how long each piece was running.
Ps bad code: WHERE id = ".$_POST['id']." - sql injection

I
Igor Samokhin, 2013-06-13
@grigor007

It's strange,
this request is slowly executed from the second time (the further, the slower)

      $res = mysql_query("INSERT INTO 
                b_lists_users_ids 
                SET user_vk_id = ".$_POST['user_vk_id']."
                , bl_acc_to_app = '1'
                , not_srch_posts_vk = '1'
                , reason = '".mysql_real_escape_string($_POST['reason'])."'
                , user_vk_id_add = '".$_SESSION['vk_id']."'
                , date_add = UNIX_TIMESTAMP()
                , user_vk_id_edit = '".$_SESSION['vk_id']."'
                , date_edit = UNIX_TIMESTAMP()
                ON DUPLICATE KEY UPDATE
                is_active = '1'
                , bl_acc_to_app = '1'
                , not_srch_posts_vk = '1'
                , reason = '".mysql_real_escape_string($_POST['reason'])."'
                , user_vk_id_edit = '".$_SESSION['vk_id']."'
                , date_edit = UNIX_TIMESTAMP()
                ");

Maybe some setting in mysql?

C
Casus, 2013-06-13
@Casus

At random: try to copy the data from the session and close it at the beginning of the script.
<?php session_start(); $sessionData = $_SESSION; session_close();

P
Petrusha Ukropov, 2013-06-14
@artishok

And if you try mysql_unbuffered_query?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question