English 中文(简体)
• 探寻文件上载所需的时间
原标题:Detect how long it takes for a file to upload (PHP)
  • 时间:2010-05-28 19:37:43
  •  标签:
  • php
  • upload

能否知道(服务器)文件上载的时间? 我的图像上载了APIC,在我的答复中,我想回上载时间(不包括文字执行时间)。

最佳回答

我认为是的。 SERVER[RequestST_TIME]ps, which indicated thestart of HTTP request, so on the person script :

$upload_time = time() - $_SERVER[ REQUEST_TIME ];

结果将是二次。

问题回答

参看这一方法实际上与科索沃相当:

  1. Send off an ajax request (right before form posts) to the server which stores a session timestamp
  2. Post the form
  3. Check difference in the receiving end :)

HTML

<?php session_start(); // must be at the top ?>

<form id="upload-form" enctype="multipart/form-data" method="post">
    <input type="file" name="datafile" size="40">
    <input type="submit" value="Send">
</form>

<script type="text/javascript">
    $(function()
    {
        $( #upload-form ).submit(function()
        {
            $.ajax({
                url:  start-timer.php ,
                type:  POST ,
                context: this,
                success: function() { this.submit(); },
            });

            return false;
        });
    });
</script>

start-timer.php

<?php session_start();
$_SESSION[ time ] = microtime(true);

upload.php

<?php 
session_start();
header( content-type: text/plain; charset=utf-8 );

if( ! isset($_FILES[ file ])
||  ! isset($_SESSION[ time ])
||  $_FILES[ file ][ error ] !== UPLOAD_ERR_OK
||  ! is_uploaded_file($_FILES[ file ][ tmp_name ]))
{
    exit( stuff went wrong... );
}

$time = microtime(true) - $_SESSION[ time ];
unset($_SESSION[ time ]);
echo round($time, 3). s ;

工作样本:

You simply can t measure anything inside the receiving script.
Just because it is started right after the upload (handled by the web-server) ends.

因此,正如Svish所说,日本宇宙航空研究开发机构在会议上发出的呼吁和时间表是最容易的解决办法。

审视这一联系。

http://prefetch.net/blog/index.php/2007/01/02/measuring-apache-request-process-time/

它表明如何没收藏匿物,以记录请求被藏匿时间。

然后,你可以使用PHP的沥青——再问——头盔资金并抽出时间。

http://php.net/manual/en/Function.apache-request-headers.php

或许可以这样说,从那时候开始清点文件,到把文件处理到处理文件地点,就算出时间?

我们需要做一些测试,因为我没有这样做。 让我知道它是否发挥作用......:

<UPDATE BY @GustavBertram:

注:我对答复进行了编辑,而不是我自己的问题,因为我想将尝试分别记录到每个答复中。

我使阿帕奇的 mo头ers得以使用,并添加了以下文字:

#/etc/apache2/mods-available/headers.conf
RequestHeader set X-Request-Received: %t

我随后更新了我的文字:

<form action="#" enctype="multipart/form-data" method="post">
Upload:<input type="file" name="datafile" size="40">
<input type="submit" value="Send">
</form>
<?php

// Get the request headers
$REQUEST_HEADERS = apache_request_headers();

// Extract $t value from header
parse_str($REQUEST_HEADERS[ X-Request-Received ]);

// Massage string to get float in seconds
$received_time = substr_replace($t,  . , 10, 0);

// Get the current microtime as float in seconds
$current_time = microtime(1);

$upload_time = $current_time - $received_time;

echo $received_time . " 
 <BR />";
echo $current_time . " 
 <BR />";

echo $upload_time;

我在我的当地机器和网络的一个遥远的机器上测试了它,有700个用户。

At Apache 2.2.22 and PHP 5.2.17, I use apache_response_headers() lead with flush() command, another way it does not work, i receive header with one variable. ob_end_flush() did not help me. REQUEST_TIME variable of $_SSERVER is elegant equivalent but pay attention this works from PHP 5.1.

我有简单的逻辑。

当图像被贴在上载时

在变量中节省起算时间,并为上载Status =0等设定另一个变量,然后当上载时,上载即为上载Status = 1的变量,并节省另一变数的终点时间。

如果上载Status = 1,那么从尾时间起就减去起算时间,你将获得上载时间。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签