How to do a bandwidth speed test using php

Post Reply
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

How to do a bandwidth speed test using php

Post by Saman » Wed Jun 16, 2010 6:00 am

Features
Upload and download bandwidth tests
Interactive user experience
Very customizable
Saves results in a database
Restrict to particular networks / IP Addresses
Customizable look
Customizable maximum file sizes

Download
speedtest-1.1.zip
(60.13 KiB) Downloaded 401 times
Installation Instructions

1- Download speedtest.zip

2- Extract the contents of the archive

3- Customize speedtest.cfg with your settings. The comments throughout the file should help explain all of the settings. At a very minimum you need to configure the base_url, upload_url, and image_path settings

4- Customize the .html files as you would like (optional):header.html Customized "header" that you can have displayed on each page. The contents of this file are displayed before any output from the speed test scripts
footer.html Customized "footer" that will be displayed on each page
welcome.html Displayed if auto_start is off when you go to index.php
unallowed.html Page that is displayed if the user is not allowed to use the speedtest
style.css Basic style sheet - customize as needed

5- Upload all of the files to a directory on you web site

6- NOTE: upload.cgi is a Perl script that needs to be put in a directory that allows CGI's to be executed. The process for this will depend on your hosting provider. In the best case scenario, you can add the following to a .htaccess file in your directory:

Code: Select all

    Options ExecCGI
If this is not allowed or does not work, then most hosts provide a /cgi-bin/ directory that you should be able to use. You will need to modify the $config_file variable inside upload.cgi to point to the correct directory where your speedtest.cfg is stored.

upload.cgi also relies on the Time::HiRes perl module in order to make a precise measurement of the time that it takes to upload the content. If you get an Internal Server Error (HTTP 500 Error) when trying to use upload.cgi, then you may not have Time::HiRes installed. Check your apache error log file for more detailed information. If Time::HiRes is not installed you should install it yourself. If you are on a managed hosting account, you may need to have your hosting provider install it for you.

If you can't get upload.cgi to work correctly, then you can set skip_upload to 1 in the [upload] section of speedtest.cfg

7- If you plan on saving results to a databae, you will need to include the necessary fields in the [database] section of the config file. You will also need to create the database table for the results to be saved in.

You can use the following SQL to create a table named "speedtest"

Code: Select all

        CREATE TABLE `speedtest` (
        `id` int(10) unsigned NOT NULL auto_increment,
        `ip` int(11) NOT NULL default '0',
        `ip_string` varchar(15) NOT NULL default '',
        `timestamp` datetime NOT NULL default '0000-00-00 00:00:00',
        `downspeed` varchar(15) NOT NULL default '',
        `upspeed` varchar(15) NOT NULL default '',
        PRIMARY KEY  (`id`)
        ) ;
No interface is provided in order to view the results. I'm assuming that if you have a need to view the results, they you are probably in charge of a server or network and should know how to do this.

8- That should be it. Please check http://www.brandonchecketts.com/speedtest/ for the latest news and additional troubleshooting step

SECURITY WARNING:

The speedtest.cfg file is a plain text file that could potentially be viewed through your web server. Since this file may contain a database username and password, it's important that visitors not be able to read it. You should put the following inside a .htaccess file in your directory.

Code: Select all

    <Files *.cfg>
        Deny From All
    </files>

Then try to read http://www.yoursite.com/speedtest/speedtest.cfg and make sure you can't read it.

Troubleshooting
Speed test results seem accurate up to about 10 Mbps. At speeds higher than that, the large chunks of data start to slow down the JavaScript engine on the client.
Post Reply

Return to “PHP & MySQL”