Skip to content

Issue #460: Locking session while saving large content - #461

Open
katerynadegtyariova wants to merge 1 commit into
h5p:stablefrom
katerynadegtyariova:issue460-stable
Open

Issue #460: Locking session while saving large content#461
katerynadegtyariova wants to merge 1 commit into
h5p:stablefrom
katerynadegtyariova:issue460-stable

Conversation

@katerynadegtyariova

Copy link
Copy Markdown

The description of the problem and steps to repeat are provided in Issue #460.

Profiling shows that 95% of time is spent inside h5p.classes.php: H5PExport > createExportFile > $zip->Close() call:

https://github.com/h5p/h5p-php-library/blob/c84217f8414c06ebabe3dedb046a77c42c2f0dbf/h5p.classes.php#L1931

However, the library submodule is used not only with Moodle. For this reason the patch is proposed for Moodle plugin.

The solution for the session locking would be to write_close() the session before finishing zip file. It will allow other pages to use session without waiting on the file operation to finish.

The main concern is that framework::messages() should not be called before the session is closed.
My testing confirms that framework::messages() is not called at all when the file content is being saved.

public static function messages($type, $newmessage = null, $code = null) {
static $m = 'mod_hvp_messages';
if ($newmessage === null) {
// Return and reset messages.
$messages = isset($_SESSION[$m][$type]) ? $_SESSION[$m][$type] : array();
unset($_SESSION[$m][$type]);
if (empty($_SESSION[$m])) {
unset($_SESSION[$m]);
}

framework::messages() is only called when the content is loaded for viewing or editing. However, in such case the session is not closed (the session will be closed only before the file storing).

The testing method is described in Issue #460. Although the file saving can take considerable time (which is expected for large files), the session is not locked and another page can be opened in a separate tab without giving errors.

@otacke otacke added the bug Something isn't working label Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Development

Successfully merging this pull request may close these issues.

2 participants