「セッションロック (Dev docs)」の版間の差分

提供:MoodleDocs
移動先:案内検索
編集の要約なし
編集の要約なし
8行目: 8行目:
  $CFG->debugsessionlock = 5; // 秒
  $CFG->debugsessionlock = 5; // 秒
セッションがN秒以上ロックされた場合、ロックを保持している他のページの詳細に関してデバッグコールが実行されます。
セッションがN秒以上ロックされた場合、ロックを保持している他のページの詳細に関してデバッグコールが実行されます。
== Session unlocking ==
== セッションロック解除 Session unlocking ==
By default core assumes that you might need to mutate the $SESSION object so it will hold a lock on the session until the page finished and a shutdown handler will release the session lock.
By default core assumes that you might need to mutate the $SESSION object so it will hold a lock on the session until the page finished and a shutdown handler will release the session lock.
デフォルトではcoreは$SESSIONオブジェクトを変異させる必要があるかもしれないと想定されているため、ページが終了してシャットダウンハンドラがセッションロックを解放するまでセッションロックを保持することになります。
If you are working on any page which is potentially long running, then you should cleanly separate logic which runs early which could mutate the session from the long running processin code and unlock the session.
If you are working on any page which is potentially long running, then you should cleanly separate logic which runs early which could mutate the session from the long running processin code and unlock the session.
もし、あなたが長時間実行される可能性のあるページで作業している場合、セッションを変異させる可能性のある早期に実行されるロジックと長時間実行されるprocessinコードとを明確に分離して、セッションロックを解除する必要があります。
  \core\session\manager::write_close();
  \core\session\manager::write_close();
== Read only session in pages ==
== Read only session in pages ==

2023年5月27日 (土) 15:00時点における版

作成中です - Mitsuhiro Yoshida (トーク)

あなたが通常のmoodleページを作成してconfig.phpをインクルードした場合、デフォルトで大量のmoodleブートストラップが実行された後、$SESSIONグローバルが設定されます。 これは安全な出発点ですが、より高性能なコードを書きたい場合、可能な限り、セッションロックを減らすか排除した方が良いでしょう。

セッションロック問題のデバッグ

もし「遅いページ」があり、あなたがそれをプロファイリングして、当該ページがロックの解放を待っているのだと判明した場合、これは全体のパフォーマンスを向上させるために簡単に修正できる可能性があります。

$CFG->debugsessionlock = 5; // 秒

セッションがN秒以上ロックされた場合、ロックを保持している他のページの詳細に関してデバッグコールが実行されます。

セッションロック解除 Session unlocking

By default core assumes that you might need to mutate the $SESSION object so it will hold a lock on the session until the page finished and a shutdown handler will release the session lock. デフォルトではcoreは$SESSIONオブジェクトを変異させる必要があるかもしれないと想定されているため、ページが終了してシャットダウンハンドラがセッションロックを解放するまでセッションロックを保持することになります。 If you are working on any page which is potentially long running, then you should cleanly separate logic which runs early which could mutate the session from the long running processin code and unlock the session. もし、あなたが長時間実行される可能性のあるページで作業している場合、セッションを変異させる可能性のある早期に実行されるロジックと長時間実行されるprocessinコードとを明確に分離して、セッションロックを解除する必要があります。

\core\session\manager::write_close();

Read only session in pages

For this to work, READONLY sessions must be enabled as well needing your code to support it. Not all session

If you know ahead of time that you will never mutate the session, but you still need to be able to read it, then you can declare your page to be read only. This will mean your page will never block the session in another http request.

define('READ_ONLY_SESSION', true);

Read only sessions in web services

The same is possible in web services. When you declare your web service you can specify it will not need a session lock:

    'core_message_get_unread_conversations_count' => array(
        'classname' => 'core_message_external',
        'methodname' => 'get_unread_conversations_count',
        'classpath' => 'message/externallib.php',
        'description' => 'Retrieve the count of unread conversations for a given user',
        'type' => 'read',
        'ajax' => true,
        'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
        'readonlysession' => true, // We don't modify the session.
    ), 

No session at all

If your script doesn't actually need $SESSION in the first place then save even more processing and locks by declaring:

define('NO_MOODLE_COOKIES', true);

No config is needed

Going to the absolute extreme, if you do not even need the full moodle bootstrap to run then you can skip it via:

define('ABORT_AFTER_CONFIG', true);