首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何缩短此脚本的执行时间?

如何缩短此脚本的执行时间?
EN

Stack Overflow用户
提问于 2011-02-13 11:11:36
回答 1查看 1.9K关注 0票数 0

一个多星期以来,我一直试图优化MySQL查询的脚本。最后,我决定在我的生产环境上安装Xdebug,我发现其中一些结果很有趣:

  1. 使用MySQL慢速查询,它不会在服务器上返回更高的工作。所以这意味着我的查询一点也不慢。也许这是因为我目前还没有很多数据。安装memcached的
  2. 将我的一些PHP执行时间从5分钟缩短到了1或2分钟,但也出现了一些问题。Memcached不会为我的用户返回一个新条目。很明显,大约1分钟后,我会从内存中获取数据。因此,无论如何,我决定暂时不实现memcached。这样的用户不多。不管怎样,时间过得很慢。--

这就是我的服务器应用程序的场景。但几天前,出于安全考虑,我实现了一个新模块,为我的应用程序上的所有对象创建了一个加密密钥。为此,我实现了数据氪t类,它显然在我的笔记本电脑上的开发环境中工作得很好。

为什么要来寻求帮助?使用winCachegrind查看了Xdebug分析--我发现数据氪的实例化需要37,218 my来执行,我的一些文件显示了10或15行,每一行都在动态地生成和加密密钥。

数据加密类的大量使用是一个问题。它在每个脚本文件中都使用。因此,我需要一个新的快速类,以便在我的应用程序中使用加密哈希。

有人能给我推荐一个吗?或者我该怎么做才能让数据更快地运行?

如果你想看看我的剧本,请告诉我。

代码语言:javascript
复制
    <div class="property-holder">
<?php

    require BASE_DIR.'/controller/listing.php';

    if(is_array($rows)){
        echo $nav;  
    ?>
<div id="properties-listing" class="content center container-wraps">
<?php
        //$crypt =  new datacrypt();
        foreach($rows as $row){

                //$pkey = $crypt->encrypt($row['property_type'].'-'.$row['property_id'].'-'.$row['broker_id'].'-'.$row['company_id']);
                    if($row[property_type] == 'development'){
                    $picture = (( $row['dev_logo']!='')?'<img class="ui-action" rel="open"  src="'.HOST.'thumbs/80x80/dev/'.$row['dev_logo'].'" />':'<img src="'.HOST.'imgss/noimage.jpg" width="80" height="80" />');
                    }else{
                    $picture = (( $row['image']!='')?'<img class="ui-action" rel="open"  src="'.HOST.'thumbs/80x80/'.$row['property_id'].'/'.$row['image'].'" width="80" height="80" />':'<img src="'.HOST.'imgss/noimage.jpg" width="80" height="80" />');
                    }
                    $prop.=' <div class="listing clearfix shadowbox" id="'.$pkey.'" ref="MLS-'.$row['property_id'].'"  >';
                    $prop.='<div class="listing-photo  left"><a href="#property-view" rel="load-content">'.$picture.'</a></div>';
                    $prop.='<div class="left listing-holder clearfix">';                    
                        $prop.='<h2 class="title"><span class="location"> '.$row['city'].', '.$row['estate'].', '.$row['country'].' </span> '.$row['property_name'].' <em class="company"> ( MLS-'.$row['property_id'].' )</em> '.($_SESSION[company_id]==$row[company_id]?'<span class="company ui-icon ui-icon-heart" ></span>':'').'</h2>';
                        $prop.='<div class="listing-description clearfix"><ul>';

                        $prop.='<div class="threebox left">';
                        $prop.='<li><span>'.T_('Tipo de propiedad').'</span><strong>'.$row['category'].' </strong></li>';   
                        $prop.='<li><span>'.T_('unidad/es disponible').'</span>'.$row['units'].'</li>'; 
                        $prop.='</div>';
                        $prop.='<div class="threebox left">';
                        if((boolean)$row['negotiation']){
                        $prop.='<li>'.T_('precio disponible a').'<strong> '.T_('negociaci&oacute;n').'</strong></li>';  
                        }

                        if((boolean)$row['for_rent'] ){
                                if($row['property_type'] == 'development'){
                                $prop.='<li><span><strong>'.T_('en renta desde:').'</strong></span> $ '.number_format($row['min_rent']).' '.T_('hasta').' '.$row['max_rent'].'</li>';   
                                }else{
                                $prop.='<li><span><strong>'.T_('renta:').'</strong></span> $ '.number_format($row['rent_price']).' '.$row['currency_type'].'</li>'; 
                                }

                            }
                            if((boolean)$row['for_sale'] ){
                                if($row['property_type'] == 'development'){
                                $prop.='<li><span><strong>'.T_('en venta desde:').'</strong></span> $ '.number_format($row['min_sale']).' '.T_('hasta').' '.$row['max_sale'].'</li>';   
                                }else{
                                $prop.='<li><span><strong>'.T_('venta:').'</strong></span>  $ '.number_format($row['sale_price']).' '.$row['currency_type'].'</li>';    
                                }
                            }
                            if((boolean)$row['for_vacational'] ){
                            $prop.='<li><span><strong>'.T_('renta vacacional:').'</strong></span> $ '.number_format($row['min_price']).'  / $ '.number_format($row['mid_price']).' / $ '.number_format($row['hig_price']).' '.$row['currency_type'].'</li>';    
                            }
                            $prop.='<li><span>'.T_('Tipo de propiedad').'</span><strong>'.($row[property_type]=='development'?T_('desarrollo'):$row['category']).' </strong></li>'; 
                            if($row[property_type]=='inventory'){

                            $prop.='<li><strong>'.T_('Pertenece a desarrollo').'</strong></li>';    
                            }

                        $prop.='</div>';
                        $prop.='<div class="threebox left">';
                        $prop.='<li><span>'.T_('Ba&ntilde;os:').'</span><strong> '.$row['bathrooms'].'</strong></li>';  
                        $prop.='<li><span>'.T_('Habitaciones:').'</span> '.$row['bedrooms'].'</li>';    
                        $prop.='</div>';
                        $prop.='</ul></div>';
                    $prop.='</div>';
                    $prop.='<div class="options" >
                            <ul>';
                    $prop.='<li><a rel="open" href="'.HOST.LANG.'/property/?k='.urlencode($pkey).'" title="'.T_('Ver descripcion completa de la propiedad.').'" ><span class="ui-button-icon-primary ui-icon ui-icon-contact"></span>'.T_('ver m&aacute;s').'</a></li>';
                    $prop.='<li><a rel="note" href="#" title="'.T_('Agregar nota a esta propiedad, este mensaje es solo entre la empresa que lista la propiedad y tu como broker.').'" ><span class="ui-button-icon-primary ui-icon ui-icon-tag"></span>'.T_('nota').'</a></li>';
                    $prop.='<li><a rel="info" href="#" title="'.T_('Ver informacion de la empresa que lista esta propiedad.').'" ><span class="ui-button-icon-primary ui-icon ui-icon-contact"></span>'.T_('info').'</a></li>';
                    $prop.='<li><a rel="open" href="'.HOST.LANG.'/pdf/?k='.urlencode($pkey).'" title="'.T_('Descargar presentaci&oacute;n en pdf').'"  title="'.T_('Descargar presentaci&oacute;n en pdf de esta propiedad').'"><span class="ui-button-icon-primary ui-icon ui-icon-circle-arrow-s"></span>'.T_('PDF').'</a></li>';
                    $prop.='</ul>
                        </div>';
                        /*
                    $prop.='<div class="metadata threebox center shadowbox content darknessbox" >';
                        $prop.='<h3>'.$row[companyname].'</h3>';
                        $prop.='<p>'.$row[companyaddress].' </p>';
                        $prop.=' < '.$row[companyweb].' >  '.$row[companyphone].' </p>';
                        $prop.='<p><strong>'.$row[brokername].'</strong> < '.$row[brokeremail].' >  <br />'.$row[brokerphone].'  &mdash; '.$row[brokermobile].'</p>';
                        $prop.='<em>MLS-'.$row['id'].' </em>: <strong>c. '.$row[commission].'</strong>';
                    $prop.=' </div>'; */
                $prop.=' </div>';
            }
            echo $prop;
    ?>
        </div>

    <?php
        echo $nav;  
    }else{
        message(T_('Wow!, lo sentimos no hay propiedades para mostrar'),'warning');
    }
?>
</div>
EN

回答 1

Stack Overflow用户

发布于 2011-02-13 12:33:46

提示: 1-使用模板将PHP代码与HTML代码分离。

代码语言:javascript
复制
   2- print  time()  to generate the time before execution and after the execution. 

示例:

代码语言:javascript
复制
  <?

  $start=time();
  some code here 1 ,,,,,,,,
  $after1=time();
  $total1=$after1-$start;
  echo "total time for execution this part:  ".$total1

 ?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4983789

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档