Changeset 12908 for trunk/i.php


Ignore:
Timestamp:
Jan 17, 2012, 7:09:32 AM (13 years ago)
Author:
rvelices
Message:

feature 2548 multisize - ability to choose displayed size on index page
-added some logs on i.php (configurable) to measure the perf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/i.php

    r12865 r12908  
    2929defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', $conf['data_location'].'i/');
    3030
     31function get_moment()
     32{
     33  $t1 = explode( ' ', microtime() );
     34  $t2 = explode( '.', $t1[0] );
     35  $t2 = $t1[1].'.'.$t2[1];
     36  return $t2;
     37}
    3138function trigger_action() {}
    3239function get_extension( $filename )
     
    6471// end fast bootstrap
    6572
     73function ilog()
     74{
     75  global $conf, $ilogfh;
     76  if (!$conf['enable_i_log']) return;
     77  if(!$ilogfh)
     78  {
     79    $dir=PHPWG_ROOT_PATH.$conf['data_location'].'tmp/';
     80    if (!mkgetdir($dir) or ! ($ilogfh=fopen($dir.'i.log', 'a')) )
     81      return;
     82  }
     83  fwrite($ilogfh, date("c") );
     84  foreach( func_get_args() as $arg)
     85  {
     86    fwrite($ilogfh, ' ' );
     87    if (is_array($arg))
     88    {
     89      fwrite($ilogfh, implode(' ', $arg) );
     90    }
     91    else
     92    {
     93      fwrite($ilogfh, $arg);
     94    }
     95  }
     96  fwrite($ilogfh, "\n");
     97}
    6698
    6799function ierror($msg, $code)
     
    93125}
    94126
     127function time_step( &$step )
     128{
     129  $tmp = $step;
     130  $step = get_moment();
     131  return intval(1000*($step - $tmp));
     132}
    95133
    96134function parse_request()
     
    160198  }
    161199  array_shift($deriv);
    162 
    163200  $page['coi'] = '';
    164201  if (count($deriv) && $deriv[0][0]=='c' && $deriv[0][1]=='i')
    165202  {
    166203    $page['coi'] = substr(array_shift($deriv), 2);
    167     preg_match('#^[a-z]{4}$#', $page['coi']) or ierror('Invalid center of interest', 400);
     204    preg_match('#^[a-zA-Z]{4}$#', $page['coi']) or ierror('Invalid center of interest', 400);
    168205  }
    169206
     
    188225  }
    189226
    190   if ($req[0]!='g' && $req[0]!='u')
     227  if (!is_file(PHPWG_ROOT_PATH.$req.$ext) and
     228      is_file(PHPWG_ROOT_PATH.'../'.$req.$ext) )
    191229    $req = '../'.$req;
    192230
     
    226264
    227265$page=array();
     266$begin = $step = get_moment();
     267$timing=array();
     268foreach( explode(',','load,rotate,crop,scale,sharpen,watermark,save,send') as $k )
     269{
     270  $timing[$k] = '';
     271}
    228272
    229273include_once( PHPWG_ROOT_PATH .'/include/derivative_params.inc.php');
     
    288332
    289333$image = new pwg_image($page['src_path']);
     334$timing['load'] = time_step($step);
    290335
    291336$changes = 0;
     
    300345  $changes++;
    301346  $image->crop( $crop_rect->width(), $crop_rect->height(), $crop_rect->l, $crop_rect->t);
     347  $timing['crop'] = time_step($step);
    302348}
    303349
     
    307353  $image->resize( $scaled_size[0], $scaled_size[1] );
    308354  $d_size = $scaled_size;
     355  $timing['scale'] = time_step($step);
    309356}
    310357
     
    312359{
    313360  $changes += $image->sharpen( $params->sharpen );
     361  $timing['sharpen'] = time_step($step);
    314362}
    315363
     
    346394  }
    347395  $wm_image->destroy();
     396  $timing['watermark'] = time_step($step);
    348397}
    349398
     
    358407$image->write( $page['derivative_path'] );
    359408$image->destroy();
     409$timing['save'] = time_step($step);
    360410
    361411send_derivative($expires);
     412$timing['send'] = time_step($step);
     413
     414ilog('perf',
     415  basename($page['src_path']), $o_size, $o_size[0]*$o_size[1],
     416  basename($page['derivative_path']), $d_size, $d_size[0]*$d_size[1],
     417  time_step($begin),
     418  $timing);
    362419?>
Note: See TracChangeset for help on using the changeset viewer.