PHP MySQL small query timeout, have to set limit t

2019-05-10 13:03发布

I am getting PHP timeout errors when calling mysql_query() for a relatively small query, so i have to set the limit to 10.

Fatal error: Maximum execution time of 120 seconds exceeded in C:\xampp\htdocs\data.php on line 19

I have removed the loop from the code, the code seems to hang at the mysql_query() function..


mysql_connect("192.168.50.250",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT T.Tag as 'Device', y.alarmdesc as 'AlarmType', a.Active, a.Cleared FROM gencore.gc_alarms a JOIN ist.Tree T ON(T.DeviceId = a.DeviceId)  JOIN GenCore.gc_alarmtypes y ON (a.alarmType = y.aid) LIMIT 10";

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
?>
<table class="sortable resizable editable tableStyle2">
<tr class="headerStyle">
<th>Device</th>
<th>AlarmType</th>
</tr>
<?php
 $i=0;
while ($i < $num) 
{

    $f1=mysql_result($result,$i,"Device");
    $f2=mysql_result($result,$i,"AlarmType");

?>

<tr>
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>

</tr>

<?php
    $i++;
} 
?>

</body>
</html>

The query executes very quick from anywhere else, and is only 340 rows, does anyone have any pointers how to retrieve the small table from the DB?

Regards Johan

2条回答
我想做一个坏孩纸
2楼-- · 2019-05-10 13:36

You can extend the timeout with mysql.connect_timeout key in php.ini.

I also notice that mysql_close() should be positioned after using mysql_result, and you have a typo: mysql_numrows should be mysql_num_rows

查看更多
趁早两清
3楼-- · 2019-05-10 13:49

If you're having trouble with queries that don't complete in time, try running the SHOW FULL PROCESSLIST; command in a MySQL console. That will show you any locks that may be preventing your query from writing or reading data. Your problems sounds like there may be an active lock on the table you're trying to read from.

查看更多
登录 后发表回答