Login Register






Measure time between php scripts filter_list
Author
Message
Measure time between php scripts #1
Hello everyone.
I would really like some help with the following:

So, I am currently working on a PHP rating system where each time two pictures are presented to every visitor and he chooses the best in his opinion. At this point I would like to know how much time is spent from the time someone clicks on an image (meaning that selects it) since the next page load (with new images).

The problem here is that i am using two php scripts that do the whole work and from what I have seen on the Internet there is no free script that can measure time between more than one php loading script.

How is this working?
Simply at the index page two random numbers are generated which will be the ID of each image in the mysql database and using these IDs the images will be printed on screen.
Now these images work like links. When someone clicks on one of the two the data of the vote are transfered (images are links) to another php script that actually does the whole work ,counting and calculating everything that will be put in the database and when this script and when this script has run all the commands it redirects the visitor back to the index page and where two other images will be printed for him to choose.

I want somethink like a calculator to start at the top of the index page and to end when the second script is over and it will redirect back to the index page.

I have found this but works only when one php script is used:
This part goes before the main commands:
PHP Code:
$time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $start = $time;

And this part goes at the end and prints the result:
PHP Code:
$time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $finish = $time; $total_time = round(($finish - $start), 4); echo 'Page generated in '.$total_time.' seconds.';

Please help. Thanks in advance!

-ReTi0n

Reply

RE: Measure time between php scripts #2
I saw your code here: http://www.phpjabbers.com/measuring-php-...php17.html Smile

Anyway, you wrote:
Quote:At this point I would like to know how much time is spent from the time someone clicks on an image (meaning that selects it) since the next page load (with new images).

From the server side you can only calculate the time from the moment the page was requested to the moment the next page is requested (or if using Ajax, to the next request!), it is really hard for the server to know when the user really selected something on the client side because the clock between the two (client and server) is not in sync!

So... what I would do, is to use a client side scripting (JavaScript), that will definitly be more precise... and it work like this:
- Once the page is loaded calculate page load time (plt), there is an gloabal event in JS for that...
- do some math to find the result: result = ist - plt and save i in a ... cookie? (I am thinking out load), what is ist? see next
- once the user select something, handle the event in JS, and calculate the time, lets call it image selection time (ist)
- when sending the request... you will send "result" to the server about the previous result!

The only bad thing in my solution (that I am not sure that it is valid so please don't flame at me lol), is that you will miss the first and the last reasults, which I am not sure that you will actually need!

Happy coding
[Image: wvBFmA5.png]

Reply

RE: Measure time between php scripts #3
I knew that some time in the future i'd need javascript. Havent used it much and dont know much. Your idea sounds logical Im just not sure how to combine javascript with php and cookies, it would take some time for sure to do this due to lack of js knowledge or I could do make the two scripts one. That would take less time, and time is somethink i dont really have Biggrin
Thanx 4 the idea @Ligeti

Reply

RE: Measure time between php scripts #4
... sounds like you are giving up!?! Never give up! How you will ever learn anything if you do? Maybe (and why not?) YOU ARE the greatest JavaScript man ever existed who changed the way we think about distribution systems through his code that calculates the time between any two global events by synchronizing the client/server clock?!? You think I am silly? well... Facebook is silly!

Thanks
[Image: wvBFmA5.png]

Reply

RE: Measure time between php scripts #5
(02-13-2014, 10:34 PM)Ligeti Wrote: ... sounds like you are giving up!?! Never give up! How you will ever learn anything if you do? Maybe (and why not?) YOU ARE the greatest JavaScript man ever existed who changed the way we think about distribution systems through his code that calculates the time between any two global events by synchronizing the client/server clock?!? You think I am silly? well... Facebook is silly!

Thanks

Hahaha I love the way you say things man ,you might be right, I should try it , Id learn js sometime in the future sure so maybe this is a sign from god saying its time :Laughing::Laughing::Laughing:
Thanx again1!

Reply