Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,781 members, 7,820,731 topics. Date: Tuesday, 07 May 2024 at 08:24 PM

How To Test Network Speed With Php - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / How To Test Network Speed With Php (814 Views)

Nigerian Challanges Google Loading Speed With His New Project. / Do Nigerians Use Google To Test Internet Speed Rather Than Search? / Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: (2) (3) (4)

(1) (Reply) (Go Down)

How To Test Network Speed With Php by c34s3r(m): 7:52am On Nov 23, 2014
how to check network speed with PHP....
not everybody has high speed internet so it is good practice to test the internet speed...this is done in PHP by sending a large amount of data and noting the time it takes to transmit it....
let's write the script
<?php
// Retrieve the data to send to the user
$data = file_get_contents("textfile.txt"wink;
// Determine the data's total size, in Kilobytes
$fsize = filesize("textfile.txt"wink / 1024;
// Define the start time
$start = time();
// Send the data to the user
echo $data;
// Define the stop time
$stop = time();
// Calculate the time taken to send the data
$duration = $stop - $start;
// Divide the file size by the number of seconds taken to transmit it $speed = round($fsize / $duration,2);
// Display the calculated speed in Kilobytes per second
echo "Your network speed: $speed KB/sec.";
?>
that is it ...
the script produces something like....
your network speed is 55KB/sec
need more PHP help,head over to www.Kinwap.com...

drop your comments
Re: How To Test Network Speed With Php by c34s3r(m): 7:55am On Nov 23, 2014
my number is 08140314215 you can add Me on watsapp or see more of my post and tutorials at www.Kinwap.com
Re: How To Test Network Speed With Php by jboy01(m): 11:02am On Nov 23, 2014
bingcrawler:
kai,PHP'll be sweet o.
What's all those $$$s doing there?
Lols
lol. The $ is use in declaring variable in php.
Re: How To Test Network Speed With Php by dwebdesign(m): 4:29pm On Nov 23, 2014
textfile.txt file?
what content is in there and where is the file.?

the php function, file_get_contents(); is to extract the information in textfile.txt.

so where is the file or if i create the file, what content should i put in? any content?

Please make your tutorials clear to those still learning.

Good tut.
Re: How To Test Network Speed With Php by c34s3r(m): 4:39pm On Nov 23, 2014
the text file.txt is the file you are parsing for transmission...you use file_get_contents() to get the file actual size....
Re: How To Test Network Speed With Php by c34s3r(m): 4:41pm On Nov 23, 2014
you should create the file yourself and put it in a place where the SERVER can find it
Re: How To Test Network Speed With Php by dwebdesign(m): 7:01pm On Nov 23, 2014
This I wanted you to make clear. An upcoming person may not get u earlier but now it's more clearer.
Re: How To Test Network Speed With Php by c34s3r(m): 8:39pm On Nov 23, 2014
yes sir
Re: How To Test Network Speed With Php by c34s3r(m): 8:11pm On Nov 26, 2014
make random images show every time a page loads....in this script we will create 5 images which the page will pick Any at random to display each time a page loads...this trick makes it look like you update your site frequently....
first let's create an array of five images...
$images=array()
$images[0]="mylo.jpg";
$images[1]="mylo2.jpg";
$images[2]="mylo3.jpg";
$images[3]="mylo4.jpg";
$images[4]="mylo5.jpg";

remember that PHP starts counting from zero so follow as is....
now we will create randomness using PHPs random function...
$random=Rand(1,5);..
create randomness from 1-5 ....
now we will use a switch to pick the images at random...
switch($random){
case 1:
print "<img src=\"$images[0]\"alt=\"an image\"width=\"150\"height=\"200\"/>";
Break;
case 2:
print "<img src=\"$images[1]\"alt=\"an image\"width=\"150\"height=\"200\"/>";
break;
case 3:
print "<img src=\"$images[2]\"alt=\"an image\"width=\"150\"height=\"200\"/>";
break;
case 4:
print "<img src=\"$images[3]\"alt=\"an image\"width=\"150\"height=\"200\"/>";
break;
case 5:
print "<img src=\"$images[4]\"alt=\"an image\"width=\"150\"height=\"200\"/>";
break;
default:
print "no images found";
break;
}
test and see ......happy testing..
Re: How To Test Network Speed With Php by c34s3r(m): 8:15pm On Nov 26, 2014
explaining super global arrays in PHP....
$_SERVER contains header related information ....path and script location on a sever...not all servers provide most of this information,most will omit some and some will provide some....
this are the parameters related to the $_SERVER global array....
REMOTE_ADDR
provides the IP address of the current system viewing a page...
PHP_SELF
it provides the filename of the currenty executing script..it is used mostly for one page form submissions...
SERVER_ADDR
the IP address of the SERVER the script IS currently executing ....
SERVER_NAME
the name of the SERVER executing the current script...example is localhost
'SERVER_PROTOCOL'
Name and revision of the information protocol via which the page was requested; i.e. 'HTTP/1.0'
REQUEST_METHOD'
the type of method used to send the rrqursti.e. 'GET', 'HEAD', 'POST', 'PUT'.
'REQUEST_TIME'
The timestamp of the beginning of the request.
REQUEST_TIME_FLOAT
'The timestamp of the start of the request, with microsecond precision.
'QUERY_STRING
'The query string, if any, via which the page was accessed.
'DOCUMENT_ROOT'
The document root directory under which the current script is executing, as defined in the server's configuration file.
'HTTP_ACCEPT'
Contents of theAccept:header from the current request, if there is one.'HTTP_ACCEPT_CHARSET'
Contents of theAccept-Charset:header from the current request, if there is one. Example: 'iso-8859-1,*,utf-8'.'HTTP_ACCEPT_ENCODING
'Contents of theAccept-Encoding:header from the current request, if there is one.Example: 'gzip'.'HTTP_ACCEPT_LANGUAGE'
Contents of theAccept-Language:header from the current request, if there is one.Example: 'en'.
'HTTP_CONNECTION'
Contents of theConnection:header from the current request, if there is one. Example: 'Keep-Alive'.
'HTTP_HOST
'Contents of theHost:header from the current request, if there is one.'HTTP_REFERER'
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify
HTTP_REFERER
as a feature. Inshort, it cannot really be trusted.
'HTTP_USER_AGENT'
Contents of theUser-Agent:header from the current request, if there is one. This is astring denoting the user agent being which is accessing the page. A typical example is:Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586). Among other things, you can use this value withget_browser()to tailor yourpage's output to the capabilitiesof the user agent.
REMOTE_HOST
the host name from which the current page is been viewed
'REMOTE_PORT'
The port being used on the user's machine to communicatewith the web server.'REMOTE_USER'
The authenticated user.'REDIRECT_REMOTE_USER
'The authenticated user if the request is internally redirected.'
SCRIPT_FILENAME
'The absolute pathname of the currently executing script.
SERVER_PORT
'The port on the server machine being used by the web server for communication. For default setups, this will be '80'
SERVER_SIGNATURE'
String containing the server version and virtual host name which are added to server-generated pages, if enabled.

more loading......stay tuned

(1) (Reply)

Help!! I Need Advice On How To Create A Website For A Company / I Want To Sell This Domain Name: Allpcdownloads.com / Came Across A Vps For $0.01 Just Now.

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 24
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.