php响应时间太长了

时间:2015-10-06 13:36:04

标签: php mysql json odbc visual-foxpro

从VFP数据库结果中获取结果我遇到了一些问题...我的php脚本占用的时间很长 - 大约30分钟,但它应该短得多......

所以有代码负责获取数据库结果:

$connect = odbc_connect("RIS", "", "", SQL_CUR_USE_DRIVER) or die("Error in connection ".  odbc_errormsg($connect));
    $array = array();
    $info = array();

    $from = $_GET['from'];
    $to = $_GET['to'];

    $rez_nap = odbc_exec($connect, "
                                        select
                                            pacientid as pac_pk,
                                            datanapr,
                                            ocered,
                                            rtgapparat,
                                            doctor as doc_naprav,
                                            pk_na,
                                            data_opis,
                                            arst_opis as id_arst_opis
                                        from
                                            napravlenie
                                        where
                                            not arst_opis == '0000' and
                                            not arst_opis == '' and
                                            datanapr between {^".$from."} and {^".$to."}
                        ") or die(odbc_errormsg());
    while($row_nap = odbc_fetch_array($rez_nap))
    {
        echo "<pre>";
        var_dump($row_nap);

        $rez_opis = odbc_exec($connect, "
                                            select
                                                opis as opisanie,
                                                doctor as doc_opis
                                            from
                                                opisanie_rtg
                                            where
                                                pacientid = '".$row_nap["pac_pk"]."' and
                                                data = '".$row_nap["data_opis"]."' and
                                                ocered = '".$row_nap["ocered"]."'
                             ") or die(odbc_errormsg());
        while($row_desc = odbc_fetch_array($rez_opis))
        {
            $op = explode('@#$', $row_desc['opis']);
            $opisanie = iconv( "cp1257", "utf-8", trim( addslashes($op[1]) ) );
            $t_nr_i = substr($op[0], 12);
            $ttt = explode("[", $t_nr_i);

            if ( strlen($ttt[0]) > 12 )
            {
                $tt_nr_is = explode("-", $ttt[0]);
                $t_nr_is_t = substr($tt_nr_is[0], 0, 8);
                $t_nr_is_t_2 = substr($tt_nr_is[0], 8, 5);
                $row_desc["nr_is"] = $t_nr_is_t."-".$t_nr_is_t_2;
            }
            else
            {
                $t_nr_is_t = substr($ttt[0], 0, 8);
                $t_nr_is_t_2 = substr($ttt[0], 8, 5);
                $row_desc["nr_is"] = $t_nr_is_t."-".$t_nr_is_t_2;
            }
            $row_desc['opis'] = $opisanie;
            /////////////////////////////////////////////////////////////////////////////////////////////////////
            $rez_apparat = odbc_exec($connect, "
                                select
                                    kod,
                                    gruppa,
                                    imy,
                                    prefiks
                                from
                                    apparatura
                                where
                                    kod = '".$row_nap["rtgapparat"]."'
                  ") or die("Error in apparatura.dbf - ".  odbc_errormsg($connect));
            while($row_apparat = odbc_fetch_array($rez_apparat))
            {
                $rez_app_gruppa = odbc_exec($connect, "
                                                    select 
                                                        gruppa,
                                                        prefiks,
                                                        apparati
                                                    from
                                                        apparat_gruppa
                                                    where
                                                        gruppa = '".$row_apparat["gruppa"]."'
                                                 ") or die(error_logs("Error in apparat_gruppa.dbf - ".odbc_errormsg($connect)));
                while($row_app_gruppa = odbc_fetch_array($rez_app_gruppa))
                {
                    $rez_personal = odbc_exec($connect, "
                                                        select 
                                                            s_name as doc_opis_name,
                                                            f_name as doc_opis_surname
                                                        from
                                                            personal
                                                        where
                                                            number = '".$row_nap["id_doc_opis"]."'
                                                     ") or die(error_logs("Error in personal.dbf - ".odbc_errormsg($connect)));
                    while($row_personal = odbc_fetch_array($rez_personal))
                    {
                        $row_personal["doc_opis_name"] = iconv("cp1257", "utf-8", trim($row_personal["doc_opis_name"]));
                        $row_personal["doc_opis_surname"] = iconv("cp1257", "utf-8", trim($row_personal["doc_opis_surname"]));
                        $row_personal["filial"] = "r15";

                        $info[] = array_merge($row_nap, $row_desc, $row_apparat, $row_app_gruppa, $row_personal);
                    }
                }
            }
        }
    }

    echo json_encode($info);
    odbc_close($connect);

数据库有大约80-90k行数据,我使用odbc驱动程序连接到VFP数据库,数据库也在远程服务器上...任何建议我做错了什么?因为我无法弄清楚我做错了什么......感谢您的任何建议和帮助!

P.S此外,我需要将该响应转换为JSON,然后将其保存到MySQL数据库......

编辑1 我有第二个索引: pacientid,data_opis,进入了pacient table,opisanie和napravlenie

0 个答案:

没有答案