PHP 8.5.0 Alpha 4 available for testing

Voting

: min(four, nine)?
(Example: nine)

The Note You're Voting On

frank (at) haua dot net
14 years ago
I have a cli script running that use the filesize function on a ssh2_sftp connection. It has the >2Gb limit issue, while it does not have that issue locally. I have managed to get around this by doing a "du -sb" command through ssh2_shell.

The following function takes the ssh2_connect resource and the path as input. It may not be neat, but it solves the problem for the moment.

<?php
function fSSHFileSize($oConn, $sPath) {
if(
false !== ($oShell = @ssh2_shell($oConn, 'xterm', null, 500, 24, SSH2_TERM_UNIT_CHARS))) {
fwrite($oShell, "du -sb '".$sPath."'".PHP_EOL);
sleep(1);
while(
$sLine = fgets($oShell)) {
flush();
$aResult[] = $sLine;
}
fclose($oShell);
$iSize = 0;
if(
count($aResult) > 1) {
$sTemp = $aResult[count($aResult)-2];
$sSize = substr($sTemp, 0, strpos($sTemp, chr(9)));
if(
is_numeric(trim($sSize))) {
$iTemp = (int)$sSize;
if(
$iTemp > "2000000000") $iSize = $iTemp;
}
}
return
$iSize;
}
return
0;
}
?>

<< Back to user notes page

To Top