如何获得延迟

时间:2013-04-09 06:54:13

标签: php android

我有一个问题,它让我发疯。在我的应用程序中,我需要获取本地标记的值,服务器请求的延迟,服务器标记以及对应用程序的响应延迟。

我能得到的唯一值是本地标记,服务器标记和完整循环的时间(请求+响应)。那么如何获得请求延迟和响应延迟。

2 个答案:

答案 0 :(得分:0)

如果您使用php执行请求,可以使用以下内容:

<?php
    // start a timer
    $start_time = microtime(true);
    // do some network stuff
    // example is read google.com
    $buffer = file_get_contents('http://www.google.com');
    // echo the current time minus the start time
    echo number_format(microtime(true) - $start_time, 5) . ' seconds';

答案 1 :(得分:0)

long sendtime,latncyTime;   
HttpPost httppost = new HttpPost("http://your-url.com");

            List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>(
                    2);
            nameValuePairs.add(new BasicNameValuePair("username",
                    "ARUN"));
            nameValuePairs.add(new BasicNameValuePair("password",
                    "****"));
            try {
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

sendtime=System.currentTimeMillis();
                HttpResponse response = httpclient.execute(httppost);
                if (response.getStatusLine().getStatusCode() == 200) {
latncyTime=System..currentTimeMillis()-sendtime;



                }

            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();

            }