运行一堆查询后,表不断崩溃

时间:2016-05-06 02:09:18

标签: php mysql

表'geoPoint'被标记为崩溃,应该修复

我用一个有500行的文件调用这个函数 这导致500个查询被快速连续调用...

这可能不是最有效的,但为什么它会不断崩溃地理点表?

CSVImport($table, $fields,$_FILES["file"["tmp_name"],$cardID,2);

function CSVImport($table, $fields, $file,$cardID,$intype) {
    if($file == null)
    {
        echo "Error No File";
         die('Cannot open uploaded file.');
    }
    $handle = fopen($file,'r');
    if(!$handle) die('Cannot open uploaded file.');

    $tmpfname = tempnam("/tmp", "FOO");
    copy($file, $tmpfname);
    $row_count = 0;
    $rows = array();

    while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {
        $row_count++;
        $itemcount = 0;

        $NAME = $data[0];
        $LAT = $data[1];
        echo "<td>{$LAT}</td>";
        $LON = $data[2];
        echo "<td>{$LON}</td>";
        $STREETNUM = $data[3];
        echo "<td>{$STREETNUM}</td>";
        $STREETNAME = $data[4];
        echo "<td>{$STREETNAME}</td>";
        $CITY = $data[5];
        echo "<td>{$CITY}</td>";
        $ZIP = $data[6];
        echo "<td>{$ZIP}</td>";
        $COUNTY = $data[7];
        echo "<td>{$COUNTY}</td>";
        $UUID = $data[8];
        echo "<td>{$GEOTYPE}</td>";
        $DATE = $data[9];
        echo "<td>{$DATE}</td>";
        $GARCOMUUID = $data[10];
        echo "<td>{$GARCOMUUID}</td>";
        $CITYUUID = $data[11];
        echo "<td>{$CITYUUID}</td>";
        $CITYSPECUUID = $data[12];
        $latRound = number_format((float)$LAT, 3, '.', '');
        $lonRound = number_format((float)$LON, 3, '.', '');
        number_format((float)$foo, 2, '.', '');

        echo "<td>{$CITYSPECUUID}</td>";

        $custquery="SELECT * FROM `geoPoint` WHERE `lat` LIKE '%{$latRound}%' AND `lon` LIKE '%{$lonRound}%' AND `street_num` = {$STREETNUM}";

        $custre=mysql_query($custquery);
        if (!$custre) {    echo 'Could not run custre query: ' . mysql_error();    exit;    }
        $custarr = mysql_fetch_array($custre, MYSQL_ASSOC);

        if($custarr == null)
            $itemisnew = 0;
        else
        {
            $itemisnew = mysql_num_rows(custarr);
        }
        if($itemisnew == 0)
            echo "<td>NEW</td>";
        else if($itemisnew == 1)
            echo "<td>REPLACE</td>";
        else
            echo "<td>MULTIPLE!</td>";
    }

    fclose($handle);

1 个答案:

答案 0 :(得分:2)

表崩溃不是PHP中可能导致的。这是由于硬件故障(内存不良或磁盘损坏),配置错误或MySQL中的错误造成的。

当表崩溃时,MySQL的错误日志中是否显示任何内容?如果MySQL被设置为使用太多内存,它可能会绊倒Linux的内存不足处理程序,这将导致MySQL进程终止,使您的表处于“脏”状态。您可能没注意到,因为许多发行版的脚本会自动监视并重新启动崩溃的守护程序。那是我的第一次猜测。