Skip to content

Instantly share code, notes, and snippets.

@fedek6
Last active June 8, 2017 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fedek6/155b9a7be4785c80166d67bd1a360d20 to your computer and use it in GitHub Desktop.
Save fedek6/155b9a7be4785c80166d67bd1a360d20 to your computer and use it in GitHub Desktop.
Benchmark method taken from Instant Share app
<?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