Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

PHP Help


  • Please log in to reply
23 replies to this topic

#1 JacobHall

JacobHall

  • Members
  • 300 posts
  • OFFLINE
  •  
  • Local time:04:55 PM

Posted 21 October 2009 - 09:33 AM

Hello,

At the moment, I have pulled together a simple PHP Script which tells the person viewing the page HOW LONG the page takes to load etc, I have gone brain dead now :thumbsup:

<?php
$ip = "youriphere"; 
$port = "yourporthere";
$start = microtime(true);
if (!$sock = @fsockopen($ip, $port, $num, $error, 5)) 
echo '<B><FONT COLOR=red>Offline</b></FONT>'; 
else{ 
$howlong = microtime(true) - $start;
echo '<B><FONT COLOR=lime>Online</b></FONT> time: ' . $howlong . ' seconds'; 
fclose($sock); 
} 
?>

I want it to look like this page http://www.spamsite.co.uk/status.php

So, after x seconds the page would state it as SLOW
after y seconds the page would state it as DOWN
after z seconds the page would state it as ACTIVE


Help is appreciated :flowers:

Edited by jacoblloyd, 21 October 2009 - 09:34 AM.


BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:55 AM

Posted 21 October 2009 - 11:10 AM

What is it that you want to measure? All you can do with PHP is measure how long the page takes to process on the server. It can not account for delays in transmission due to Internet congestion, or delays in rendering due to the client having a slow machine, multiple tabs open in the browser, or the client machine having limited resources. If you want to measure transmission time, or measure actual rendering time, you will have to do something different.

I Think a timer is a bad idea because unless you are really measuring all three, your measurement is not going to be accurate. If your measurement says that the page is fast, and it takes 30 seconds for the page to load, then you lose credibility. If your algorithm for calculating page load time comes up continuously as slow, regardless of whether or not it actually is, people are going to think it is slow. Again, you lose credibility. I am happy to help you make a timer, but I need to know what you are timing.

#3 JacobHall

JacobHall
  • Topic Starter

  • Members
  • 300 posts
  • OFFLINE
  •  
  • Local time:04:55 PM

Posted 21 October 2009 - 11:18 AM

What is it that you want to measure? All you can do with PHP is measure how long the page takes to process on the server. It can not account for delays in transmission due to Internet congestion, or delays in rendering due to the client having a slow machine, multiple tabs open in the browser, or the client machine having limited resources. If you want to measure transmission time, or measure actual rendering time, you will have to do something different.

I Think a timer is a bad idea because unless you are really measuring all three, your measurement is not going to be accurate. If your measurement says that the page is fast, and it takes 30 seconds for the page to load, then you lose credibility. If your algorithm for calculating page load time comes up continuously as slow, regardless of whether or not it actually is, people are going to think it is slow. Again, you lose credibility. I am happy to help you make a timer, but I need to know what you are timing.



Well, I am using fsockopen() and I would put in the IP Address of the host, It would then open the IP Address and calculate how long it takes to load. I basically want it to do that but if it takes longer than say E seconds to load, it would show a SLOW image as I think Images would be 100x easier than implementing this code into a table

Regards

#4 JacobHall

JacobHall
  • Topic Starter

  • Members
  • 300 posts
  • OFFLINE
  •  
  • Local time:04:55 PM

Posted 21 October 2009 - 11:59 AM

So, to recap

If the server takes up to say 4 seconds to load, It is said to be Online with an Online image showing

If the server takes more than 4 seconds to load, It will be shown with an Offline image :thumbsup:

Thanks for your help Grovicous, in advance

#5 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:55 AM

Posted 21 October 2009 - 12:05 PM

Ok, I'll try this again; what consists of a page load? Is it the time it takes to initialize it on the server? Is it the time to initialize on the server plus transmission time? Is it initialization time, plus transmission time, plus time it takes to render in the browser? Is it just the render time? I can't tell you if your approach is right unless I specifically know exactly what you mean by load time. Load time to me is the time it takes to render in the browser. My IT friends consider load time to be all three steps that I outlined above.

#6 JacobHall

JacobHall
  • Topic Starter

  • Members
  • 300 posts
  • OFFLINE
  •  
  • Local time:04:55 PM

Posted 21 October 2009 - 12:17 PM

Sorry, I am pretty new to this :S

Ermm, the time it takes for the page to initalize

Edited by jacoblloyd, 21 October 2009 - 12:20 PM.


#7 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:55 AM

Posted 21 October 2009 - 01:02 PM

Then all you need to do is get the time at the beginning of the PHP script, and get the time at the end of the php script. But here is the problem. By the time you get the end of your code, presumably it will already have dealt with the code that is used to draw the button. To get around this, the button will have to be drawn at the bottom of the page. Example:
<?php

	$startTime = time();
	
	for($i=0; $i<50000000; $i+=1){
		//do nothing, just loop
	}
	
	$endTime = time();
	$elapsedTime = $endTime - $startTime;

	echo ("initialization time is: " . $elapsedTime . " second(s)");


?>

That is the easiest way to do it.

#8 JacobHall

JacobHall
  • Topic Starter

  • Members
  • 300 posts
  • OFFLINE
  •  
  • Local time:04:55 PM

Posted 21 October 2009 - 01:10 PM

Ok ok, I am a stupid person :thumbsup:

Thanks for your help :flowers:

So, Would I put the code I posted earlier below the one you posted, and add the image URL/s in?

Bestest Regards

#9 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:55 AM

Posted 21 October 2009 - 01:17 PM

You set the start time at the top of your code, then deal with the rest after the rest of your code runs, so actually, your code would go in place of the dummy 'for' loop.

#10 JacobHall

JacobHall
  • Topic Starter

  • Members
  • 300 posts
  • OFFLINE
  •  
  • Local time:04:55 PM

Posted 21 October 2009 - 04:37 PM

Sorry, I don't understand how to put the code together :thumbsup:

Regards_

#11 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:55 AM

Posted 21 October 2009 - 05:43 PM

Are you not building your web pages with PHP?
<?php 

	$startTime = time();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">



<head>

<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

<title>Untitled 1</title>

</head>



<body>



<h1>I am a web page created using PHP</h1>

<h1>Today's Date is <?php echo( date("D F j"))?></h1>

<?php

	$endTime = time();

	$elapsedTime = $endTime - $startTime;

	

	echo('<h1>Elapsed Time is : ' . $elapsedTime . ' seconds</h1>');

?>



</body>



</html>


#12 JacobHall

JacobHall
  • Topic Starter

  • Members
  • 300 posts
  • OFFLINE
  •  
  • Local time:04:55 PM

Posted 21 October 2009 - 05:48 PM

Yes, but this is basically an Isolated page I am pulling to a toolbar, So I don't need a header, footer etc as all I really need is the code on the page

http://jakeh.2kmegs.com/stats.php

^^ That is what I currently have

_Regards

#13 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:55 AM

Posted 21 October 2009 - 06:18 PM

Put your code in place of the for loop that I did in the original example.

#14 JacobHall

JacobHall
  • Topic Starter

  • Members
  • 300 posts
  • OFFLINE
  •  
  • Local time:04:55 PM

Posted 21 October 2009 - 06:54 PM

<? 
$ip = "213.**.243.68"; 
$port = "80"; 
if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) 
echo '<IMG SRC="ventdown.png" ALIGN=right>'; 
else{ 
echo '<IMG SRC="ventup.png" ALIGN=right>'; 
fclose($sock); 
} 
?><? 
$ip = "216.108.23**8"; 
$port = "80"; 
if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) 
echo '<IMG SRC="paneldown.png" ALIGN=left>'; 
else{ 
echo '<IMG SRC="panelup.png" ALIGN=left>'; 
fclose($sock); 
} 
?><br><? 
$ip = "80.4.**4.28"; 
$port = "3784"; 
if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) 
echo '<IMG SRC="fhdown.png" ALIGN="middle">'; 
else{ 
echo '<IMG SRC="fhup.png" ALIGN="middle">'; 
fclose($sock); 
} 
?>
<br>
<br>
<? 
$ip = "94.1***192.76"; 
$port = "80"; 
if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) 
echo '<font size="2" face="Verdana"> DHNET is currently</font> <font size="2" face="Verdana" color="red"><b>Offline</b></font>'; 
else{ 
echo '<font size="2" face="Verdana"> DHNET is currently</font> <font size="2" face="Verdana" color="limegreen"><b>Online</b></font>'; 
fclose($sock); 
} 
?>
<br>
<br>

<? 
$ip = "213.106.**68"; 
$port = "80"; 
if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) 
echo '<font size="2" face="Verdana"> FlameHabbo is currently</font> <font size="2" face="Verdana" color="red"><b>Offline</b></font>'; 
else{ 
echo '<font size="2" face="Verdana"> FlameHabbo is currently</font> <font size="2" face="Verdana" color="limegreen"><b>Online</b></font>'; 
fclose($sock); 
} 
?>
<br>
<? 
$ip = "216.***.239.38"; 
$port = "80"; 
if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) 
echo '<font size="2" face="Verdana"> FlameHabbo DJ Panel is currently</font> <font size="2" face="Verdana" color="red"><b>Offline</b></font>'; 
else{ 
echo '<font size="2" face="Verdana"> FlameHabbo DJ Panel is currently</font> <font size="2" face="Verdana" color="limegreen"><b>Online</b></font>'; 
fclose($sock); 
} 
?>
<br>
<? 
$ip = "80.4.***.28"; 
$port = "3784"; 
if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) 
echo '<font size="2" face="Verdana"> FH Ventrilo is currently</font> <font size="2" face="Verdana" color="red"><b>Offline</b></font>'; 
else{ 
echo '<font size="2" face="Verdana"> FH Ventrilo is currently</font> <font size="2" face="Verdana" color="limegreen"><b>Online</b></font>'; 
fclose($sock); 
} 
?>


That is my current code, I have no idea what to do next despite the "for" stuff

bestest regards

#15 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:55 AM

Posted 21 October 2009 - 07:05 PM

Let's try this. Instead of this:
<?php

	$startTime = time();
	
	for($i=0; $i<50000000; $i+=1){
		//do nothing, just loop
	}
	
	$endTime = time();
	$elapsedTime = $endTime - $startTime;

	echo ("initialization time is: " . $elapsedTime . " second(s)");


?>

Check this:
<?php

	$startTime = time();
	
	***ALL OF YOUR CODE GOES HERE***
	
	$endTime = time();
	$elapsedTime = $endTime - $startTime;

	echo ("initialization time is: " . $elapsedTime . " second(s)");


?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users