Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-73834

PHP8 libxml behaviour change: unwanted network requests (was: Slow LTI tests)

    XMLWordPrintable

Details

    • MOODLE_311_STABLE, MOODLE_400_STABLE
    • MOODLE_311_STABLE
    • MDL-73834_311
    • Hide

      Requirements

      1. To be able to use both php73 and php80

      Tests

      1. Switch to php73
      2. Init PHPUnit: php admin/tool/phpunit/cli/init.php
      3. Run:

        vendor/bin/phpunit \
            --testsuite \
                mod_lti_testsuite,ltiservice_gradebookservices_testsuite \
            --testdox -v
        

      4. Verify that the tests run in less than 1 minute (60 seconds). The total time is near the end, in a line similar to this:

        Time: 00:20.670, Memory: 93.00 MB
        

      5. Switch to php80
      6. Repeat steps 2-4.
      Show
      Requirements To be able to use both php73 and php80 Tests Switch to php73 Init PHPUnit: php admin/tool/phpunit/cli/init.php Run: vendor/bin/phpunit \ --testsuite \ mod_lti_testsuite,ltiservice_gradebookservices_testsuite \ --testdox -v Verify that the tests run in less than 1 minute (60 seconds). The total time is near the end, in a line similar to this: Time: 00:20.670, Memory: 93.00 MB Switch to php80 Repeat steps 2-4.

    Description

      While working on MDL-73826 it was detected that mod/lti/tests/locallib.php unit tests are too slow (> 4 minutes). It seems that practically all the time is spent sort of "waiting" with this 4 tests (one minute each):

      $ vendor/bin/phpunit mod/lti/tests/locallib_test.php --testdox -v
      Moodle 3.11.5+ (Build: 20220208), 34b5b416393a5163a3273f298b2ab916ad126755
      Php: 8.0.15, pgsql: 13.5, OS: Darwin 20.6.0 x86_64
      PHPUnit 9.5.13 by Sebastian Bergmann and contributors.
       
      Runtime:       PHP 8.0.15
      Configuration: /Users/stronk7/git_moodle/moodle/phpunit.xml
       
      locallib_test (mod_lti\locallib_test)
      ...
      ...
      ...
       ✔ Lti get launch data default organizationid unset usehost [60410.68 ms]
       ✔ Lti get launch data default organizationid set usehost [60401.39 ms]
       ✔ Lti get launch data default organizationid set usesiteid [60440.08 ms]
       ✔ Lti get launch data default organizationid orgid override [60394.67 ms]
      ...
      ...
      

      Ideally, we should be able to be in the ms range instead of 1 minute.

      Updated description of the problem and the fix, after all the research (from commit message):

      Summary:

      • With PHP7, libxml_disable_entity_loader() was making those
        flags futile, and the DTDs were not being requested ever.
      • With PHP8, the flags get precedence and requests for the
        DTD have started to happen.
      • Those requests are not served by W3C (1 minute time-out).
      • Those DTDs aren't used by anything in code (no entity
        replacement, no validation...)

      Hence:

      • Remove the flags so it will work the same in PHP7 and PHP8.
      • Just to double ensure we don't want any remote loading
        to happen ever, add explicitly the LIBXML_NONET flag.

      Ciao

      Attachments

        Issue Links

          Activity

            People

              stronk7 Eloy Lafuente (stronk7)
              stronk7 Eloy Lafuente (stronk7)
              Andrew Lyons Andrew Lyons
              Sara Arjona (@sarjona) Sara Arjona (@sarjona)
              Gladys Basiana Gladys Basiana
              Jake Dallimore, Ilya Tregubov, Kevin Percy, Mathew May, Mihail Geshoski, Shamim Rezaie
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                14/Mar/22

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 6 hours, 50 minutes
                  6h 50m