phppup Posted April 12, 2023 Share Posted April 12, 2023 I want to assemble a multi-page questionnaire/quiz whereby submitting page 1 will lead to page 2 etc. I have locked in the time that each page loads by using unset($_SESSION['start']); if($_SESSION['start'] == ""){ $_SESSION['start'] = time(); } at the top of each page However, I am having difficulty in getting the time at submission. I realize I can simply use the start time of page 2 as the submission time for page 1, but that would technically be incorrect, right? In actuality, a page would load (and the time recorded). A person would submit after any amount of expended time (and that would be recorded) Then there would be a gap before the next page loaded. How can I effectively obtain these events? Or am I unnecessarily overthinking this? Quote Link to comment https://forums.phpfreaks.com/topic/316126-page-load-and-submit-times/ Share on other sites More sharing options...
kicken Posted April 12, 2023 Share Posted April 12, 2023 If you want to measure the time from when the page starts processing until the page is loaded in the browser, you cannot do that strictly with PHP. You'd have to capture the start time at the start of your PHP script, and the finish time via JavaScript's onload event. This metric isn't really all that useful though. How long it takes the page content to be loaded and processed will depend on the user's network speed which is beyond your control. If you're looking to optimize your page load times, you should be looking at the PHP processing and browser loading/processing separately rather than as a combined single load time. You could measure the processing time of your script in PHP by capturing the start time at the beginning of your script, then the ending time when your script ends. This metric would tell you if your PHP is slow to process, which you could use to determine if you need to improve areas of your code. Actual code profiling over just a simple load time would be better if this is your goal. For the browser side of things, the browser developer tools include profiling/performance tools to measure your pages resource load times, rendering times, etc. Quote Link to comment https://forums.phpfreaks.com/topic/316126-page-load-and-submit-times/#findComment-1607255 Share on other sites More sharing options...
ginerjm Posted April 12, 2023 Share Posted April 12, 2023 Your sample code is going to give an error every time it runs. Quote Link to comment https://forums.phpfreaks.com/topic/316126-page-load-and-submit-times/#findComment-1607256 Share on other sites More sharing options...
phppup Posted April 12, 2023 Author Share Posted April 12, 2023 @ginerjm Care to explain why? Quote Link to comment https://forums.phpfreaks.com/topic/316126-page-load-and-submit-times/#findComment-1607258 Share on other sites More sharing options...
ginerjm Posted April 12, 2023 Share Posted April 12, 2023 The first line does what? So what is the second line supposed to do for you? Quote Link to comment https://forums.phpfreaks.com/topic/316126-page-load-and-submit-times/#findComment-1607259 Share on other sites More sharing options...
phppup Posted April 12, 2023 Author Share Posted April 12, 2023 @kicken Thanks for the help, but I wasn't as clear as I should have been. I'm not interested in the page loading speeds (at this time) I am only trying to determine how long each user remained on the specific page before advancing. This would let me know if a question was too complicated, or maybe randomly answered. Hypothetically, it would take more than 3 seconds to write 500 words versus cut & pasting. Likewise, if it took 20 minutes to add 3 + 3, then maybe you were distracted from the webpage, etc. Or, maybe my design or layout is not easy enough to follow. Quote Link to comment https://forums.phpfreaks.com/topic/316126-page-load-and-submit-times/#findComment-1607260 Share on other sites More sharing options...
phppup Posted April 12, 2023 Author Share Posted April 12, 2023 @ginerjm OK, yes. Not sure if it will "error" but it was a quick example of my thought process. Now I understand that you were pointing out my loopiness. Quote Link to comment https://forums.phpfreaks.com/topic/316126-page-load-and-submit-times/#findComment-1607261 Share on other sites More sharing options...
maxxd Posted April 12, 2023 Share Posted April 12, 2023 There's always $_SERVER['REQUEST_TIME'] - you could do a diff with the previous value (that you'd stored in session). Replace the value once you've done what you need to do with the value of the diff and move on to the next page. Quote Link to comment https://forums.phpfreaks.com/topic/316126-page-load-and-submit-times/#findComment-1607268 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.