for ($x=0;$x<170400;$x++) fwrite($fh,"bandwidth");
// Close the file
fclose($fh);
?>
Now you??™ll write the script that will calculate the network speed. This script is shown
in Listing 16-4.
Listing 16-4. Calculating Network Bandwidth
// Retrieve the data to send to the user
$data = file_get_contents("textfile.txt");
// Determine the data's total size, in Kilobytes
$fsize = filesize("textfile.txt") / 1024;
// Define the start time
$start = time();
// Send the data to the user
echo "";
// Define the stop time
$stop = time();
424 CHAPTER 16 ?– NE TWORKING
// 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.";
?>
Executing this script produces output similar to the following:
Your network speed: 59.91 KB/sec.
Summary
Many of PHP??™s networking capabilities won??™t soon replace those tools already offered on
the command line or other well-established clients. Nonetheless, as PHP??™s commandline
capabilities continue to gain traction, it??™s likely you??™ll quickly find a use for some
of the material presented in this chapter, perhaps the e-mail dispatch capabilities if
nothing else.
The next chapter introduces one of the most powerful examples of how to use PHP
effectively with other enterprise technologies, showing you just how easy it is to interact
with your preferred directory server using PHP??™s LDAP extension.
Pages:
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503