Last active
June 8, 2017 12:52
-
-
Save fedek6/155b9a7be4785c80166d67bd1a360d20 to your computer and use it in GitHub Desktop.
Benchmark method taken from Instant Share app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Benchmark | |
* | |
* @category debug | |
*/ | |
public function benchmark() { | |
/** @var integer $timeStart **/ | |
$timeStart = microtime(true); | |
echo 'RUNNING BENCHMARK, PLEASE WAIT.</br>'. PHP_EOL; | |
/** @var string $name **/ | |
$name = 'test.zip'; | |
set_time_limit( 600 ); | |
/** @var string $packageDir **/ | |
$packageDir = Config::$tmpDir . DIRECTORY_SEPARATOR . 'test'; | |
if( file_exists( $packageDir ) ) { | |
/** | |
* Select packing method | |
*/ | |
// internal zipArchive | |
if( Config::$packingMethod == 'internal' ) { | |
$zipArchive = new ZipArchive(); | |
$zipArchive->open( Config::$uploadPath . DIRECTORY_SEPARATOR . $name, \ZipArchive::CREATE); | |
$zipArchive->addDirectory( Config::$tmpDir . DIRECTORY_SEPARATOR . 'test' ); | |
$zipArchive->close(); | |
} | |
// command line | |
elseif( Config::$packingMethod == 'command' ) { | |
echo 'USING COMMAND LINE MODE!<br />' . PHP_EOL; | |
/** @var $command **/ | |
$command = vsprintf_named( Config::$packingCommand, [ | |
'name' => Config::$uploadPath . DIRECTORY_SEPARATOR . $name, | |
'path' => Config::$tmpDir . DIRECTORY_SEPARATOR . 'test', | |
] ); | |
exec( $command, $output, $return ); | |
echo $command . '<br />' . PHP_EOL; | |
echo 'RUNNING AS: ' . get_current_user() . '<br />' . PHP_EOL; | |
echo implode( ', ', $output ) . ' WITH CODE ' . $return . '<br />' . PHP_EOL; | |
// Return will return non-zero upon an error | |
if( $return !== 0) { | |
$error = true; | |
echo 'COMMAND LINE ERROR!<br />' . PHP_EOL; | |
} | |
} | |
} else { | |
echo "SORRY BUT TEST DIR DOES NOT EXIST. PLEASE CREATE IT.</br>" . PHP_EOL; | |
} | |
/** @var float $time Execution time. **/ | |
$time = number_format(( microtime(true) - $timeStart), 4); | |
echo "FINISHED SUCCESSFULLY IN: $time SECONDS.</br>" . PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment