Facebook Fun - Time

Posted on 2009-02-20
Last Modified: 2012-05-06
Hello all,

I would like to have a simple picture (I will accept a button if it's to difficult to use images) that when I click it starts a timer.  When I click stop it stops the timer and shows the time to 5 (if possible) decimal places.  I would like to do this within facebook (not in an iframe but using FBML)

1) Click "Start"
2) Time starts ticking - Visually shows counting up on screen
3) Click "Stop"
4) Display the seconds passed, to 5dp, from when the start and stop buttons were pressed

I hope this makes sense?

Any advice would be apreciated, Alan.
Question by:ammo12kmf
    LVL 14

    Expert Comment

    by:Ionut A. Tudor
    i'm not aware of facebok system, but looks like you want a client side function but you posted in PHP Category, in this case you'll find better support in the EE JavaScript Category or try to explain better what you need to achieve in PHP ?
    LVL 107

    Accepted Solution

    Alan, I'm sure you can build this for the Facebook platform.  I'm not a user of FBML, but the PHP portion is pretty simple.

    At the start, you would make an AJAX call.  The background script would set this:
    $start = microtime(TRUE);

    ... and return a signal to display a DIV with a timer image in it.  (I would suggest an animated spinning clock or something like that).

    At the stop, you would make another AJAX call.  The background script would set this:
    $stop = microtime(TRUE);
    $duration = number_format($duration,5);

    ... and return a signal to replace the DIV image with the text giving the duration.

    So that is the code framework.  The central issues you may find go to the responsiveness of the internet and the app load at Facebook.  On a busy day, the latency between the client mouse-click and the backend application can be significant.

    HTH, ~Ray

    Author Closing Comment

    You are right, client side is the way forward, many thanks, Alan.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now