I’ve noticed that sometimes mysql_query() on particular query in my script executes immediately and sometimes it takes (almost exactly) 0.1 of a second. I wrote a simple script to test it:
mysql_connect('<server>','<login>','<pass>');
mysql_select_db('<db>');
print microtime(true).'<br />';
mysql_query("select * from `messages` where `sq_id`=1");
print microtime(true).'<br />';
mysql_query("select * from `messages` where `sq_id`=1");
print microtime(true).'<br />';
mysql_query("select * from `messages` where `sq_id`=1");
print microtime(true).'<br />';
mysql_query("select * from `messages` where `sq_id`=1");
print microtime(true).'<br />';
And results are pretty unexpected:
0.02919600 1282686965
0.12934100 1282686965
0.22935700 1282686965
0.32934100 1282686965
0.32985500 1282686965
or, another time,
0.43041500 1282687515
0.52974500 1282687515
0.53034800 1282687515
0.53082400 1282687515
0.63109600 1282687515
Do you have any ideas why mysql_query() behaves like this?