#StartStop
1
2
3
4
5

Листинг

<?php
if(isset($_REQUEST['key'])){
    if(isset(
$_REQUEST['session']) && $_REQUEST['session']){
        
session_start();
    }
    
$key intval($_REQUEST['key']);
    if(
$key == 3) {
        
sleep(3);
    } else {
        
sleep(1); // небольшая задержка для наглядности
    
}
    echo 
$key;
    die();
}

session_start();

?>
<html>
<head>
    <script type="text/javascript" src="http://yandex.st/jquery/2.1.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function(){
            var dates = [];

            $.ajaxSetup({
                url : "/pip.php",
                beforeSend : function(a,b){
                    var key =  this.url.match(/\d/)[0];
                    dates['start_' + key] = (new Date()).getTime();
                    $(".answer_" + key + " .start").text("Start ");
                    $(".answer_" + key + " .stop").text("");
                },
                success : function(m) {
                    $(".answer_" + m + " .stop").text("stop (" + ((new Date()).getTime() - dates['start_' + m])/1000 + "s)");
                }
            });
            $("button").on("click", function(){
                dates["start_0"] = (new Date()).getTime();
                $("div").html("");
                var session = $("input:checkbox:checked").val();
                $.when(
                        $.ajax({data:{key:1, session:session}}),
                        $.ajax({data:{key:2, session:session}}),
                        $.ajax({data:{key:3, session:session}}),
                        $.ajax({data:{key:4, session:session}}),
                        $.ajax({data:{key:5, session:session}})
                    ).then(function(){
                        $("#answer").append("Done! (" + ((new Date()).getTime() - dates['start_0'])/1000 + "s)");
                    });
            });

        })
    </script>
</head>
<body>
    <button>SEND</button> <label><input type="checkbox" value="1" name="session"> Session</label>
    <hr>
    <table border="1" width="100%">
        <tr><th>#</th><th>Start</th><th>Stop</th></tr>
        <tr class="answer_1">
            <td>1</td>
            <td class="start"></td>
            <td class="stop"></td>
        </tr>
        <tr class="answer_2">
            <td>2</td>
            <td class="start"></td>
            <td class="stop"></td>
        </tr>
        <tr class="answer_3">
            <td>3</td>
            <td class="start"></td>
            <td class="stop"></td>
        </tr>
        <tr class="answer_4">
            <td>4</td>
            <td class="start"></td>
            <td class="stop"></td>
        </tr>
        <tr class="answer_5">
            <td>5</td>
            <td class="start"></td>
            <td class="stop"></td>
        </tr>
    </table>
    <div id="answer"></div>
    <hr>
    <h1>Листинг</h1>
    <?php highlight_file(__FILE__);?>
</body>
</html>