Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial php运行大数据量汇总操作时间过长网页失效 急急急!

php运行大数据量汇总操作时间过长网页失效 急急急!

Jun 23, 2016 pm 02:14 PM

PHP

运行时间大概2个小时,然后页面就失效了。有知道的朋友帮忙一下,万分感谢。

回复讨论(解决方案)

换其他语言比如C来处理统计汇总

代码呢。。。。


 function foreverselect(){
$db = Db::getInstance();
//根据编码查询数据
$id=$_REQUEST['id'];  //id
$datamonth=$_REQUEST['datamonth']; //日期
$ids=explode(',',$id); //截取
$jxtblist="";
$isok="yes"; //控制进度条标识
$datalist;//返回提示信息
$datalist1;
if(!empty($id)){
foreach($ids as $key=>$li){

$jxtbsql="select * from jx_tbprofile where id=".$li;

$jxtblist =$db-> query($jxtbsql);

foreach($jxtblist as $key=>$li1){
if($li1[execlevel]==0){ //0阶段
$list;
$success=0;//完成笔数

//先判断目的字段配置是否有误
$strtab="select * from jx_tbprofile_dtl where tableno='".$li1[tableno]."'"; //检索字段名称
$listtab=$db->query($strtab);
$strcol="show columns from ".$li1[desttable]; //获取目的表字段名称
$listcol=$db->query($strcol);

$ziduan;
$boole=false;

foreach ($listtab as $keytab=>$litab) {//配置目的表字段
foreach ($listcol as $keycol=>$licol)//目的表字段
{
if($litab[dest_column]==$licol['Field']){
$boole=true;    //两个名称相互比较,如果遇到相同的给$boole赋值true。
//echo "相等";
break;
}else{
//echo $litab[dest_column];
//echo $licol['Field'];
$boole=false; 
}
}
if(!$boole){//配置表中一个字段对应完之后获取$boole的值如果为false,就将改字段存入$ziduan函数中加入提示信息
$ziduan=$ziduan.$litab[dest_column];
$boole=false; 
break;
}
}
if(!$boole){
$datalist=$datalist."未找到目的字段".$ziduan.",配置错误!";
}else{

//清除旧数据
$sql=str_replace("|datamonth|",$datamonth,$li1[sqldeldest]);//配置的删除语句
// echo $sql;
//mysql_query($sql) or die(mysql_error()); 
if (mysql_query($sql)){
//echo mysql_query($sql);
$datalist=$datalist."原数据表已清除!
";
$sql1=$li1[remarks];//配置的查询语句
$re=str_replace("|datamonth|",$datamonth,$sql1); //替换字符

$list1 =$db-> query($re);
//mysql_query($re) or die(mysql_error()); 
$jx = M ($li1[desttable]);


foreach($list1 as $key=>$li2)
{
//$User = A($li1[tableno]); // 实例化action控制器对象


foreach ($listtab as $key=>$litab){
if(!empty($litab[mark])){//目的表中预设字段名称mark。
//echo $litab[mark];
$_POST[$litab[dest_column]]=$litab[mark];
}else{
$_POST[$litab[dest_column]]=$li2[$litab[source_column]];
}
}
//$User->fuValues1($li2);
$tru=$jx->create();
$bo=$jx->add();
$success=$success+1; //成功笔数
}


//echo date("Y-m-d h:i:s")."
".$li1[tableprofile]."结算完毕!成功".$success."笔数据。
";

$datalist=$datalist.date("Y-m-d h:i:s")."
".$datamonth.$li1[tableprofile]."结算完毕!成功".$success."笔数据。
";

}else{
$datalist=$datalist."删除语句出问题!
";

}

}

$this->assign('isok',$isok);
}
  }
}
}
}

你自己分析一下。是哪句代码执行过长,可以标示出来。


$list1 =$db-> query($re);
//mysql_query($re) or die(mysql_error()); 
$jx = M ($li1[desttable]);


foreach($list1 as $key=>$li2)
{
//$User = A($li1[tableno]); // 实例化action控制器对象


foreach ($listtab as $key=>$litab){
if(!empty($litab[mark])){//目的表中预设字段名称mark。
//echo $litab[mark];
$_POST[$litab[dest_column]]=$litab[mark];
}else{
$_POST[$litab[dest_column]]=$li2[$litab[source_column]];
}
}
//$User->fuValues1($li2);
$tru=$jx->create();
$bo=$jx->add();
$success=$success+1; //成功笔数
}

这段就是执行查询语句,然后将结果一条一条插入到目的表中。我在一张单独的表中配置了:来源表,目的表,查询语句,删除语句。在这段代码里找到配置的这条数据,然后执行查询表,插入新表的操作。其中有4条数据是量比较大的。我单独跑还挺快,但是4个连在一起跑就时间很长知道浏览器失效。

把最终生成的sql贴出来看看。表结构和索引情况如何,都描述清楚吧。

set_time_limit(0);???

把最终生成的sql贴出来看看。表结构和索引情况如何,都描述清楚吧。
在这3张表之间转换数据的jx_zy_detail_charge_belong,jx_zy_detail_charge_force,jx_zy_detail_charge

这是跑的第一条查询sql:jx_zy_detail_charge_belong->jx_zy_detail_charge_force
SELECT jx_zy_detail_charge_belong.data_month,   
         jx_zy_detail_charge_belong.inpatient_no,   
         jx_zy_detail_charge_belong.charge_date,   
         jx_zy_detail_charge_belong.op_id_code,   
         jx_zy_detail_charge_belong.charge_code,   
         jx_zy_detail_charge_belong.charge_fee,   
         jx_zy_detail_charge_belong.percentage,   
         jx_zy_detail_charge_belong.ward_code,   
         jx_zy_detail_charge_belong.dept_code,   
         jx_zy_detail_charge_belong.order_no,   
         jx_zy_detail_charge_belong.exec_unit,   
         jx_zy_detail_charge_belong.retprice,   
         jx_zy_detail_charge_belong.charge_amount,   
         jx_zy_detail_charge_belong.serial,   
         jx_zy_detail_charge_belong.group_no,   
         jx_zy_detail_charge_belong.bill_code,   
         jx_zy_detail_charge_belong.key_col,   
         jx_zy_detail_charge_belong.pat_name
    FROM jx_zy_detail_charge_belong ,jx_mz_charge_item 
   WHERE jx_zy_detail_charge_belong.data_month =  '|datamonth|' and
   jx_zy_detail_charge_belong.charge_code =jx_mz_charge_item.fee_code and
(jx_mz_charge_item.exec_unit is  null or
jx_mz_charge_item.exec_unit =' ') 
union all
SELECT jx_zy_detail_charge_belong.data_month,   
         jx_zy_detail_charge_belong.inpatient_no,   
         jx_zy_detail_charge_belong.charge_date,   
         jx_zy_detail_charge_belong.op_id_code,   
         jx_zy_detail_charge_belong.charge_code,   
         jx_zy_detail_charge_belong.charge_fee,   
         jx_zy_detail_charge_belong.percentage,   
         jx_zy_detail_charge_belong.ward_code,   
         jx_zy_detail_charge_belong.dept_code,   
         jx_zy_detail_charge_belong.order_no,   
         jx_mz_charge_item.exec_unit,  
         jx_zy_detail_charge_belong.retprice,   
         jx_zy_detail_charge_belong.charge_amount,   
         jx_zy_detail_charge_belong.serial,   
         jx_zy_detail_charge_belong.group_no,   
         jx_zy_detail_charge_belong.bill_code,   
         jx_zy_detail_charge_belong.key_col,   
         jx_zy_detail_charge_belong.pat_name
  
    FROM jx_zy_detail_charge_belong ,jx_mz_charge_item 
   WHERE jx_zy_detail_charge_belong.data_month = '|datamonth|'  and
    jx_zy_detail_charge_belong.charge_code= jx_mz_charge_item.fee_code and
jx_mz_charge_item.exec_unit is not null and
jx_mz_charge_item.exec_unit ' '
就是从一个配置表,jx_mz_charge_item 中找到本表charge_code和fee_code相同,找到配置表的exec_unit符合条件就用这个值替换原表的科室值

第二条转换查询sql:jx_zy_detail_charge_force-》jx_zy_detail_charge
select  data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,exec_unit,retprice,charge_amount,serial,bill_code,pat_name
from jx_zy_detail_charge_force
where jx_zy_detail_charge_force.exec_unit not in (select description from jx_code_ctl where item_no like 'ordept%') and data_month='|datamonth|'
union all
select  data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,exec_unit,retprice,charge_amount,serial,bill_code,pat_name
from jx_zy_detail_charge_force
 where  jx_zy_detail_charge_force.exec_unit  in (select description from jx_code_ctl where item_no like 'ordept%') and  not
             ( jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'orbill%')  or
              jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'zlbill%') ) and data_month='|datamonth|'
union all
select  data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,dept_code,retprice,charge_amount,serial,bill_code,pat_name
from jx_zy_detail_charge_force
 where   jx_zy_detail_charge_force.exec_unit  in (select description from jx_code_ctl where item_no like 'ordept%') and 
         ( jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'orbill%')  or
         jx_zy_detail_charge_force.bill_code in (select description from jx_code_ctl where item_no like 'zlbill%') ) and data_month='|datamonth|'
union all
select  data_month,inpatient_no,charge_date,op_id_code,charge_code,charge_fee,dept_code,dept_code,retprice,charge_amount,serial,bill_code,pat_name
from jx_zy_detail_charge_force
 where  jx_zy_detail_charge_force.exec_unit is null and data_month='|datamonth|'

将执行科室exec_unit字段在表jx_code_ctl中配置的科室,并且收费大类bill_code字段也在表jx_code_ctl中配置的大类中的数据的执行科室exec_unit改为开单科室dept_code



一共分为门诊和住院两组表,过程是一样的,这里是住院的流程说明,我单跑门诊和住院的第一跳sql,然后跑门诊和住院第二条sql,速度大概1个小时可以跑完,但是4条一起跑就要很久,而且页面也会挂掉。

后台执行产生所需数据,前台展示结果。

后台执行产生所需数据,前台展示结果。 是的,就是我把这4个数据量最大一起跑就很耗费时间,2个2个跑就快很多了。

用 EXPLAIN 指令检查你的 sql 指令,看看 mysql 会给你什么建议

用 EXPLAIN 指令检查你的 sql 指令,看看 mysql 会给你什么建议

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

See all articles