您好我正在使用以下代码将一个大文件(500MB)上传到 sftp 服务器。
<?php
$connection = ssh2_connect($this->host, $this->port, null);
$sftp = ssh2_sftp($connection);
$connection_string = ((int) $sftp) . $remotePath . $remoteFilename;
$stream = fopen('ssh2.sftp://' . $connection_string, 'w');
$source = fopen($localFilepath, 'r');
if (!$stream) {
throw new Exception('Could not create file: ' . $connection_string);
}
while (!feof($source)) {
// Chunk size 32 MB
if (fwrite($stream, fread($source, 33554432)) === false) {
throw new Exception('Could not send data: ' . $connection_string);
}
}
fclose($source);
fclose($stream);
但是上传速度很慢。代码在 Google Cloud Run 上运行。上传速度约为 8 MiB/s。
我也尝试通过 shell_exec 使用 lftp,但这会导致由于 Cloud Run 的更多问题。
上行链路不是问题,因为我可以通过 CURL post 发送文件而没有任何问题。
任何人都可以在这里提供帮助吗?
非常感谢,最好的,intxcc