CodeLobster IDE

php script sometimes takes a long time to execute
Page 1 of 1

Author:  adamjohnson [ Thu Nov 02, 2017 11:33 am ]
Post subject:  php script sometimes takes a long time to execute

I'm a high school teacher. I wrote an HTML/Javascript program that lets students submit their answers to an assignment using AJAX and a server-side PHP script.
Then there is another HTML program that calls a different PHP script, which generates a Leader Board, so I can display their scores on the projector. This lets the students compete for high score.
more: eco dream
The HTML page calls on this PHP script every 2 seconds, so the Leader Board constantly updates.

The basic logic of the PHP script is:
Parse $GLOBALS['HTTP_RAW_POST_DATA'] into assignment name and class list
For each student, read a file which contains their score on that assignment.
Organize this data and echo it.

When I first open the Leader Board, it sometimes loads right away, but sometimes it can take several minutes, even causing the browser to kill the page.
But once it finally works, it remains working. Every 2 seconds, the PHP is called again, and it generates its response within milliseconds. The huge delay is gone.
If I close the tab that has the Leader Board, and open it again within a few minutes, it loads immediately. But if I wait an hour and open it again, I again get the huge delay the first time the PHP is called.
more: chung cư pcc1 thanh xuân
For debugging, I had the PHP also output the time at various points in the code. Reading the file that contains the classlist and the file that contains the assignment were each done in under a second. But reading each students' grades takes about 2-3 seconds per student. But after the first execution of the PHP, it reads all 30 students grades in less than 1 second.

I've used this program for 4 years with no issues. But this summer, I bought a new domain name and a hosting plan from the same company as my original plan. I transfered all the files over, and everything was smooth and worked exactly like last year, except for this annoying delay.

If I open the Leader Board on one computer, wait for the delay to pass, close it, and then open it on another computer within a few minutes, there is no delay on the 2nd computer.
more: dự án eco dream
It's hosted on a Linux server.

Any idea why it takes so long to read file contents the first time?

Author:  Admin [ Fri Nov 03, 2017 7:02 am ]
Post subject:  Re: php script sometimes takes a long time to execute


We will try to help if You provide us with your source code.

Codelobster Team.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group