Can't run REST core_course_get_courses due to memory

Re: Can't run REST core_course_get_courses due to memory

by Matthew Davidson -
Number of replies: 2
Picture of Core developers Picture of Plugin developers

Actual error message:


cache/stores/file/lib.php


PHP Fatal error:  Allowed memory size of 2147483648 bytes exhausted (tried to allocate 1052672 bytes) in /var/www/moodle/cache/stores/file/lib.php on line 368" while reading response header from upstream


In reply to Matthew Davidson

Re: Can't run REST core_course_get_courses due to memory

by Michael Chan -

I would be interested to hear if anyone has experienced the issue raised by Matthew and found a remedy or workaround.  We are a vendor that currently has an integration with Moodle where we call the core_course_get_courses method to get all the courses.  Unfortunately, for one school, they experienced the same errors as described in this thread.

There is another thread that sort of delves into the possibility to filter the core_course_get_courses call by something like the "category id": https://moodle.org/mod/forum/discuss.php?d=348752

However, it does not appear that any work has been done in that area.

In reply to Michael Chan

Re: Can't run REST core_course_get_courses due to memory

by Michael Chan -

I've since realized there is the core_course_get_courses_by_field method that was introduced in version 3.2.  This new method is the replacement for core_course_get_courses.

Here is the syntax to filter by a category value, but you can also filter by id, course id, short name or category:

https://MOODLEURL/webservice/rest/server.php?wstoken=TOKENVALUE&wsfunction=core_course_get_courses_by_field&field=category&value=[###]&moodlewsrestformat=json

Please ensure the new API method is added as a function to the webservice token so you have the proper access.