Skip to content

Instantly share code, notes, and snippets.

@ahomu
Created February 4, 2014 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahomu/8795930 to your computer and use it in GitHub Desktop.
Save ahomu/8795930 to your computer and use it in GitHub Desktop.
画像アップロード時、レスポンスが返ってくるまでの時間を調べたい
<?php
if (!empty($_FILES)) {
echo(json_encode($_FILES));
} else {
?>
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1">
<title>Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(function() {
var $form = $('#startForm'),
$iframe = $('#endFrame'),
$log = $('#log'),
start, end;
$form.on('submit', function() {
start = Date.now();
});
$iframe.on('load', function() {
end = Date.now();
var resp = JSON.parse($iframe[0].contentWindow.document.body.innerHTML);
printTime(resp.photo.size);
});
function printTime(size) {
var time = end - start;
$log.val($log.val() + time + ' ms (' + size + 'byte )\n');
}
});
</script>
</head>
<body>
<form id="startForm" action="/test.php" method="post" enctype="multipart/form-data" target="target">
<input type="file" name="photo">
<input type="submit" value="submit">
</form>
<iframe id="endFrame" name="target" style="display: none;">
</iframe>
<textarea id="log" rows="10" cols="30"></textarea>
</body>
</html>
<?php }
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment