0

I am trying to access value from database in every 2 seconds and simultaneously 50 users.

My query looks as follows:

global $DB;

$curseId = $_REQUEST['crseId'];



if(isset($curseId)){



$qstndetails = $DB->get_records_sql('SELECT * FROM {questions} WHERE courseid=? ORDER BY id DESC LIMIT 0,1',array($curseId)); 

$qstnval = array_values($qstndetails);

}

Because of heavy load my data is not loading and I am continuously fetching it in every 2 seconds.

How can I close data base connection after fetching record?

In case of Java we can close object of Connection class. Suppose con is the object then we close connection after fetching data as con.close();.

Is there any way to close database connection after fetch data in Moodle??

Moodle version - 2.9.1

Santhucool
  • 1,656
  • 2
  • 36
  • 92
  • I'm not sure if I understand this correctly, are you performing 50 separate queries in the span of 2 seconds or are you getting 50 records at once every 2 seconds? Judging by your query, it's the first, but I can't be sure. – Andrei Sep 30 '15 at 13:35
  • @Andrew in every each 2 seconds single query performed by 50 different users from different locations to the same database!! – Santhucool Sep 30 '15 at 13:40
  • Oh, ouch. That sounds like a bummer for the database. Firstly drop the `ORDER BY`, there's only 1 record. No need to have it. I can't tell what you're using from the code. Are you using an ORM, a mapper, some self made thingy? Is it using mysqli, PDO, mysql or what? – Andrei Sep 30 '15 at 13:45
  • @Andrew Buddy its Moodle thing. I am new to Moodle. I do not know how to handle close in moodle – Santhucool Sep 30 '15 at 13:47
  • Right, right, good thing I'm paying attention -.- Anyway, `Moodle` uses postgres, and their documentation doesn't specify anything related to closing a connection. However, maybe [this](http://stackoverflow.com/questions/5108876/kill-a-postgresql-session-connection) will help you out. – Andrei Sep 30 '15 at 13:55
  • 1
    Why do you need to query the questions every 2 seconds? – Russell England Sep 30 '15 at 14:11

0 Answers0