mirror of
https://github.com/myvesta/vesta
synced 2025-08-14 10:37:42 -07:00
Merge pull request #141 from divinity76/patch-4
avoid out-of-memory serving large logfiles
This commit is contained in:
commit
fa3d9aff36
1 changed files with 24 additions and 9 deletions
|
@ -10,8 +10,6 @@ if ((!isset($_GET['token'])) || ($_SESSION['token'] != $_GET['token'])) {
|
|||
exit();
|
||||
}
|
||||
|
||||
$v_domain = $_GET['domain'];
|
||||
$v_domain = escapeshellarg($_GET['domain']);
|
||||
if ($_GET['type'] == 'access') $type = 'access';
|
||||
if ($_GET['type'] == 'error') $type = 'error';
|
||||
|
||||
|
@ -21,15 +19,32 @@ header("Content-Disposition: attachment; filename=".$_GET['domain'].".".$type."-
|
|||
header("Content-Type: application/octet-stream; ");
|
||||
header("Content-Transfer-Encoding: binary");
|
||||
|
||||
$v_domain = escapeshellarg($_GET['domain']);
|
||||
$v_domain = $_GET['domain'];
|
||||
if ($_GET['type'] == 'access') $type = 'access';
|
||||
if ($_GET['type'] == 'error') $type = 'error';
|
||||
|
||||
exec (VESTA_CMD."v-list-web-domain-".$type."log $user ".$v_domain." 5000", $output, $return_var);
|
||||
if ($return_var == 0 ) {
|
||||
foreach($output as $file) {
|
||||
echo $file . "\n";
|
||||
}
|
||||
|
||||
$cmd = implode(" ", array(
|
||||
VESTA_CMD . "v-list-web-domain-" . $type . "log",
|
||||
escapeshellarg($user),
|
||||
escapeshellarg($v_domain),
|
||||
"5000",
|
||||
));
|
||||
|
||||
if(is_callable("passthru")){
|
||||
passthru($cmd, $return_var);
|
||||
} else{
|
||||
// passthru is disabled, workaround it by writing the output to a file then reading the file.
|
||||
// this is slower than passthru, but avoids running out of RAM...
|
||||
$passthru_is_disabled_workaround_handle = tmpfile();
|
||||
$passthru_is_disabled_workaround_file = stream_get_meta_data($passthru_is_disabled_workaround_handle)['uri'];
|
||||
exec ($cmd . " > " . escapeshellarg($passthru_is_disabled_workaround_file), $output, $return_var);
|
||||
readfile($passthru_is_disabled_workaround_file);
|
||||
fclose($passthru_is_disabled_workaround_handle); // fclose(tmpfile()) automatically deletes the file, unlink is not required :)
|
||||
}
|
||||
if ($return_var != 0) {
|
||||
$errstr = "Internal server error: command returned non-zero: {$return_var}: {$cmd}";
|
||||
echo $errstr;
|
||||
throw new Exception($errstr); // make sure it ends up in an errorlog somewhere
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue