saeed_violinist Posted November 24, 2006 Share Posted November 24, 2006 Dear Friends,I am using php 5 on my local and I have finished a simple webdesign, now when I uploaded scripts, a class that calculate parsing time of a page is not working with my server that uses php 4, the class is as follow (I got it from php.net) :[code]<?php class stopwatch { private $round = 3; function __construct ( ) { $this->start = microtime(); } function now ( ) { $start = $this->math($this->start); $now = $this->math(); return round($now - $start, $this->round); } function math ($time = FALSE) { if ( !$time ) $time = microtime(); $temp = explode(' ', $time); return $temp[0] + $temp[1]; } }?>usage:$stopwatch = new stopwatch();/* some code */echo $stopwatch->now(); [/code]this class works fine on the localhost (php5) but when I try ro run it on php4 runing server I get this error message :Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/sni/domains/sni.co.ir/public_html/data/cls.php on line 9 Link to comment https://forums.phpfreaks.com/topic/28349-how-to-calculate-script-parsing-time-in-php/ Share on other sites More sharing options...
printf Posted November 24, 2006 Share Posted November 24, 2006 There are differences on how you call the constructor in PHP 4 and PHP 5, check manual for those differences, if you want to support PHP 4 and PHP 5, then use the PHP 4 way, which works with both versions.[code]<?phpclass stopwatch{ var $round; var $start; function stopwatch () { $this->start = microtime (); $this->round = 3; } function now () { $s = $this->math ( $this->start ); $e = $this->math (); return round ( $e - $s, $this->round ); } function math ( $t = false ) { if ( ! $t ) { $t = microtime (); } return array_sum ( explode ( ' ', $t ) ); }}?>[/code]printf Link to comment https://forums.phpfreaks.com/topic/28349-how-to-calculate-script-parsing-time-in-php/#findComment-129701 Share on other sites More sharing options...
saeed_violinist Posted November 24, 2006 Author Share Posted November 24, 2006 thank you printf , your change was great.Actually I have startet learning php just about a week and every day I learn a new thing in this nice forum and site.I just can say : thank you guys. Link to comment https://forums.phpfreaks.com/topic/28349-how-to-calculate-script-parsing-time-in-php/#findComment-129720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.