mirror of
https://github.com/moodle/moodle.git
synced 2025-04-25 10:26:17 +02:00
MDL-78002 moodlenet: Always close the request stream explicitly
And do it as soon as it's not needed any more. Else, only _destruct() / shutdown / gc will, and that can be problematic if many streams are open, or, under some environments like Windows that consider the stream underlying files still busy, because they have not been closed.
This commit is contained in:
parent
5252124e35
commit
2b61e95a69
@ -72,16 +72,23 @@ class moodlenet_client {
|
||||
|
||||
$moodleneturl = $this->oauthclient->get_issuer()->get('baseurl');
|
||||
$apiurl = rtrim($moodleneturl, '/') . self::API_CREATE_RESOURCE_URI;
|
||||
$stream = $file->get_psr_stream();
|
||||
|
||||
$requestdata = $this->prepare_file_share_request_data(
|
||||
$file->get_filename(),
|
||||
$file->get_mimetype(),
|
||||
$file->get_psr_stream(),
|
||||
$stream,
|
||||
$resourcename,
|
||||
$resourcedescription,
|
||||
);
|
||||
|
||||
return $this->httpclient->request('POST', $apiurl, $requestdata);
|
||||
try {
|
||||
$response = $this->httpclient->request('POST', $apiurl, $requestdata);
|
||||
} finally {
|
||||
$stream->close(); // Always close the request stream ASAP. Or it will remain open till shutdown/destruct.
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user