我有基于Laravel 5.1的项目,所以我遇到了通过curl将文件发送到另一台主机的问题。在我的PHP conf中我有memory_limit是128M,并且通过CURL我发送的文件大小为100mb,(我正在使用Laravel Queue),但是我得到了以下错误的响应
允许内存大小为134217728字节耗尽(试图分配 31860068字节)PHP
我不想在我的PHP conf中更改memory_limit
$storage = $this->configs[ 'storage' ];
if( isset( $this->configs[ 'old_storage' ] ) ) {
$old_storage = $this->configs[ 'old_storage' ];
} else {
throw new \Exception( 'Not found old storage' );
}
$files = $old_storage->files()->withTrashed()->get();
try {
if( $old_storage->testConnection()[ 'status' ] != 'true' ) {
throw new \Exception( ufl( 'disk::disk.not_connection' ) . ' ' . $old_storage->name );
}
if( $storage->testConnection()[ 'status' ] != 'true' ) {
throw new \Exception( ufl( 'disk::disk.not_connection' ) . ' ' . $storage->name );
}
foreach( $files as $file ) {
try {
$stream = $file->readStream();
$file->setStorage( $storage->id );
$file->storage()->getDriver()->putStream( $file->getRealDestination(), $stream );
$file->putStream( $file->getRealDestination(), $stream );
} catch( \Exception $e ) {
$file->setStorage( $storage->id );
}
$file->save();
}
$old_storage->is_active = 0;
$old_storage->status = DiskStorage::STATUS_OK;
$old_storage->save();
$old_storage = null;
$storage->is_active = 1;
$storage->status = DiskStorage::STATUS_OK;
$storage->save();
$storage = null;
} catch( \Exception $e ) {
//Откат
foreach( $files as $file ) {
$file->setStorage( $old_storage->id );
$file->save();
}
$storage->status = DiskStorage::STATUS_OK;
$storage->save();
$old_storage->status = DiskStorage::STATUS_OK;
$old_storage->save();
throw new \Exception( $e->getMessage() );
}
我正在使用同步驱动程序和通过webdav进行文件传输