-
-
Notifications
You must be signed in to change notification settings - Fork 877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
read larger chunks from sftp in stream wrapper #1452
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,14 @@ class Stream | |
*/ | ||
private $notification; | ||
|
||
/** | ||
* Buffer of data being read | ||
* | ||
* @var string | ||
* @access public | ||
*/ | ||
private $buffer = ''; | ||
|
||
/** | ||
* Registers this class as a URL wrapper. | ||
* | ||
|
@@ -315,16 +323,25 @@ private function _stream_read($count) | |
// return false; | ||
//} | ||
|
||
$result = $this->sftp->get($this->path, false, $this->pos, $count); | ||
if (isset($this->notification) && is_callable($this->notification)) { | ||
if ($result === false) { | ||
call_user_func($this->notification, STREAM_NOTIFY_FAILURE, STREAM_NOTIFY_SEVERITY_ERR, $this->sftp->getLastSFTPError(), NET_SFTP_OPEN, 0, 0); | ||
return 0; | ||
if (strlen($this->buffer) < $count) { | ||
// read 80k chunks from sftp even though php will only request 8k chunk | ||
// this allows us to minimize the overhead of making sftp requests | ||
$chunk = $this->sftp->get($this->path, false, $this->pos, 81920); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make the 81920 a parameter? I think there is a mechanism for that on stream construction. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what bantu is talking about is this:
Other options are discussed at https://www.php.net/manual/en/wrappers.ssh2.php There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, "stream context" is what I was referring to. |
||
if (isset($this->notification) && is_callable($this->notification)) { | ||
if ($chunk === false) { | ||
call_user_func($this->notification, STREAM_NOTIFY_FAILURE, STREAM_NOTIFY_SEVERITY_ERR, $this->sftp->getLastSFTPError(), NET_SFTP_OPEN, 0, 0); | ||
return 0; | ||
} | ||
// seems that PHP calls stream_read in 8k chunks | ||
call_user_func($this->notification, STREAM_NOTIFY_PROGRESS, STREAM_NOTIFY_SEVERITY_INFO, '', 0, strlen($chunk), $this->size); | ||
} | ||
// seems that PHP calls stream_read in 8k chunks | ||
call_user_func($this->notification, STREAM_NOTIFY_PROGRESS, STREAM_NOTIFY_SEVERITY_INFO, '', 0, strlen($result), $this->size); | ||
|
||
$this->buffer .= $chunk; | ||
} | ||
|
||
$result = substr($this->buffer, 0, $count); | ||
$this->buffer = substr($this->buffer, $count); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is nitpicky but... you could do |
||
|
||
if (empty($result)) { // ie. false or empty string | ||
$this->eof = true; | ||
return false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this say
@access private
?