05-08-2008, 12:22 PM
|
|
|
Confirmed User
Join Date: May 2005
Posts: 2,737
|
Quote:
Originally Posted by GrouchyAdmin
You kinda screwed this up a bit.
Code:
<?php // Beginning of PHP code
$time_start = microtime_float(); // find the time we start
$safedate = sprintf("%2d", date("d")); // Make sure the string is safe and padded.
$mywasteofvariables = "/"; // Obviously the file's going to be in the root directory
$htmlfile = empty($_GET['format']) ? "html" : $_GET['format']; // HTML is .html.
$htmlfile = preg_replace("/[^a-z0-9\\040\\.\\-\\_\\\\]/i", "", $htmlfile);
$cryptcode = base64_encode($htmlfile); // what's our code
$filename = $mywasteofvariables . $safedate . '.' . $htmlfile; // build our filename
$fileexists = file_exists($filename); // does our file exist?
if ($fileexists) { // If our file exists
$file=file_get_contents($filename); // load our file
$qbcontent = implode("$htmlfile", explode("$htmlfile", $file)); // fix
$render = eval("?>".stripslashes($qbcontent)."<? "); // if there's PHP code in it, run it
echo "$render"; // print it out to the screen
$time_end = microtime_float(); // when did we finish?
$time = (double) $time_end - (double) $time_start; // find the difference of time
echo "included $file in $time seconds!!!\n"; //killer stats
} // end of function
exit; // quit PHP
// copied from PHP.net or something I dont really know what it does
if (!function_exists('file_get_contents')) {
function file_get_contents($filename, $incpath = false, $resource_context = null)
{
if (false === $fh = fopen($filename, 'rb', $incpath)) {
trigger_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING);
return false;
}
clearstatcache();
if ($fsize = @filesize($filename)) {
$data = fread($fh, $fsize);
} else {
$data = '';
while (!feof($fh)) {
$data .= fread($fh, 8192);
}
}
fclose($fh);
return $data;
}
}
// something else i found on php.net - we can now time this function!!!!
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
?>
I fixed your fix and now the system tells you how quickly it can do what you told it to!
|
Looking good, but since we're dealing with time, we should use strftime and setlocale:
Code:
<?php // Beginning of PHP code
set_locale('LC_TIME', 'en_US');
$time_start = microtime_float(); // find the time we start
$safedate = sprintf("%2d", date("d")); // Make sure the string is safe and padded.
$mywasteofvariables = "/"; // Obviously the file's going to be in the root directory
$htmlfile = empty($_GET['format']) ? "html" : $_GET['format']; // HTML is .html.
$htmlfile = preg_replace("/[^a-z0-9\\040\\.\\-\\_\\\\]/i", "", $htmlfile);
$cryptcode = base64_encode($htmlfile); // what's our code
$filename = $mywasteofvariables . $safedate . '.' . $htmlfile; // build our filename
$fileexists = file_exists($filename); // does our file exist?
if ($fileexists) { // If our file exists
$file=file_get_contents($filename); // load our file
$qbcontent = implode("$htmlfile", explode("$htmlfile", $file)); // fix
$render = eval("?>".stripslashes($qbcontent)."<? "); // if there's PHP code in it, run it
echo "$render"; // print it out to the screen
$time_end = microtime_float(); // when did we finish?
$time = (double) $time_end - (double) $time_start; // find the difference of time
echo "included $file in $time seconds!!!"; //killer stats
echo "IT IS NOW " . strftime("%H:%M:%S") . "!!!\n";
} // end of function
exit; // quit PHP
// copied from PHP.net or something I dont really know what it does
if (!function_exists('file_get_contents')) {
function file_get_contents($filename, $incpath = false, $resource_context = null)
{
if (false === $fh = fopen($filename, 'rb', $incpath)) {
trigger_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING);
return false;
}
clearstatcache();
if ($fsize = @filesize($filename)) {
$data = fread($fh, $fsize);
} else {
$data = '';
while (!feof($fh)) {
$data .= fread($fh, 8192);
}
}
fclose($fh);
return $data;
}
}
// something else i found on php.net - we can now time this function!!!!
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
?>
__________________
PHP-MySQL-Rails | ICQ: 342500546
|
|
|