开发者

How to reduce the execution time of this script?

For more than a week I have been trying to optimize my scripts for MySQL queries. Finally I decided to install Xdebug on my production environment and I found some of the results funny:

  1. Using the MySQL slow query it doesn't return me a higher work on the server. So it means my queries are not slow at all. Perhaps this is because I don't have many data as yet.
  2. Installing the memcached reduced some of my PHP execution time, from 5 mins to 1 or 2 mins sometimes, but some issues came on. Memcached does not return a new entry for my users. Obviously I'm taking datas from memory about 1 minute later of database. So anyway I decide I wouldn't implement memcached for now. There are not many users to work with some like that. Anyway time speed goes slowly.

That's the scenery for my server app. But a few days ago I implemented a new module for security reasons, creating a encrypted key for all my objects on my app. I implemented the datacrypt class for that, it works perfectly on my development enviroment on my laptop obviously.

Why did I came to ask for help? Looking into the Xdebug profiling using winCachegrind I found that the instantiation of datacrypt takes 37,218ms for execution, some of my files show 10 or 15 rows and each of those rows makes and encrypted key on the fly.

The high use of datacrypt class is a problem. It is used in every script file. So I need to get a new fast class to make an encrypted hash to use in my app.

Can anyone could recommend me one? Or what can I do to make datacrypt run faster?

If you want to take a look at my scripts let me know.

    <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>


tips: 1- use template to separate the PHP code from the HTML code.
2- print time() to generate the time before execution and after the execution.

example:

  <?

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

 ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜