Results 1 to 9 of 9
-
04-27-2011, 07:35 AM #1Junior Guru Wannabe
- Join Date
- May 2010
- Posts
- 36
PHP - how to get remote server load time?
If I want to know my server's time load then I use this
PHP Code:number_format(microtime(true) - $_SERVER['REQUEST_TIME']
i.e: google load time = 0.55ms
yahoo load time = 0.1 ms
Please help
-
04-27-2011, 08:03 AM #2
Hello,
Place this php file on your remote server and use iFrame on your 2nd server.
<?php
$uptime = exec("uptime");
$parts = split("load average:", $uptime);
$load = split(", ", $parts[1]);
echo "Current load: " . $load[0];
?>
or
<?php
function server_load()
{
$load_file = "/proc/loadavg";
$handle = fopen($load_file, "r");
$contents = fread($handle, 1024);
fclose($handle);
$loads = explode(" ", $contents);
return $loads[0];
}
?>
or
<?php echo `cat /proc/loadavg | cut -d" " -f1`; ?>Dewlance® Shared/Reseller/Master Reseller - US/UK/EU/FRK/CA - SSD
WHMCS ReadyMadeKB - Tutorials for cPanel/InterWorx/Softaculous& Growing..
DemoTiger.com - Buy Demo Videos for your Hosting Company
-
04-27-2011, 08:09 AM #3
Sorry, I just found a good script for checking remote server load time.
Don't forget to replace site name and maybe port(I think 80 is default and you don't need to change port)
<?php
// attempt to open a socket on port 80 (HTTP) to the site in question
// 30 is a timeout value, in seconds
// if the connection completely fails, fsockopen() will return 0 and put error
// code and messages into $errno and $errstr, respectively
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
// report the error if the connection failed.
echo "$errstr ($errno)<br />\n";
}
else {
// put whatever code for a good connection here
}
// close the socket
fclose($fp);
}
?>
and I think script is using fopen so you need to enable fopen in your .php.ini.Dewlance® Shared/Reseller/Master Reseller - US/UK/EU/FRK/CA - SSD
WHMCS ReadyMadeKB - Tutorials for cPanel/InterWorx/Softaculous& Growing..
DemoTiger.com - Buy Demo Videos for your Hosting Company
-
04-27-2011, 08:35 AM #4Junior Guru Wannabe
- Join Date
- May 2010
- Posts
- 36
OK, this test the connection if fail or not within 30 seconds.
If the connection is good, how to know load time of www.example.com in ms?
-
04-27-2011, 08:48 AM #5
Yes,
<?php
// attempt to open a socket on port 80 (HTTP) to the site in question
// 30 is a timeout value, in seconds
// if the connection completely fails, fsockopen() will return 0 and put error
// code and messages into $errno and $errstr, respectively
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
// report the error if the connection failed.
echo "$errstr ($errno)<br />\n";
}
else {
// put whatever code for a good connection here
}
// close the socket
fclose($fp);
}
?>
Dewlance® Shared/Reseller/Master Reseller - US/UK/EU/FRK/CA - SSD
WHMCS ReadyMadeKB - Tutorials for cPanel/InterWorx/Softaculous& Growing..
DemoTiger.com - Buy Demo Videos for your Hosting Company
-
04-27-2011, 08:52 AM #6Junior Guru Wannabe
- Join Date
- May 2010
- Posts
- 36
hmm, but the code you posted needed to put it on remote server?
what If I want to check google.com load time.
What i mean is same as http://www.iwebtool.com/speed_test?domain=google.com
-
04-27-2011, 09:24 AM #7
Its a site speed tester, you can find a lots of site speed tester script.
You want to check site speed test or server load?
hmm, but the code you posted needed to put it on remote server?
what If I want to check google.com load time.Dewlance® Shared/Reseller/Master Reseller - US/UK/EU/FRK/CA - SSD
WHMCS ReadyMadeKB - Tutorials for cPanel/InterWorx/Softaculous& Growing..
DemoTiger.com - Buy Demo Videos for your Hosting Company
-
04-27-2011, 12:04 PM #8Junior Guru Wannabe
- Join Date
- May 2010
- Posts
- 36
-
05-03-2011, 09:36 PM #9Newbie
- Join Date
- Jun 2010
- Location
- Los Angeles
- Posts
- 26
from your linux console or through php's exec(), do:
time wget -p http://www.google.com >/dev/null 2>&1
it'll give you the results in milliseconds
Similar Threads
-
Rsync High Load On Remote Server
By prasant4u in forum Dedicated ServerReplies: 3Last Post: 02-05-2011, 04:01 PM -
Replicating a (remote) MySQL database to improve PHP execution time
By shought in forum Programming DiscussionReplies: 15Last Post: 11-04-2010, 04:05 PM -
PHP Load time too big
By Oakii in forum Web Design and ContentReplies: 2Last Post: 04-18-2005, 03:41 AM -
remote server uptime and load average?
By WFWH in forum Hosting Security and TechnologyReplies: 6Last Post: 10-28-2004, 05:16 PM