php ajax请求时间过长,与cURL和PHP结合的AJAX请求需要太长时间才能加载

我正在使用xampp在本地计算机上工作,并且每个其他ajax请求的工作都非常快速。我目前的应用程序需要21秒加载3.5千字节的数据。与cURL和PHP结合的AJAX请求需要太长时间才能加载

如果你问我,这有点慢。那么我的软件在做什么?

该软件有4个单选按钮。用户选择一个,然后一个AJAX请求创建

var radio = $('input[name="selection"]:checked').val();

var hidden = $('#hiddenFive').val();

$.ajax

({

type: 'GET',

url: 'curl.php',

data: {type: radio, region: 'Hampshire', hidden: hidden},

success: function(response, textStatus, XMLHttpRequest)

{

var obj = jQuery.parseJSON(response);

var strin = '';

for(var i = 0; i < obj.length; i++)

{

strin += "Name of " + radio + ": " + obj[i].name + " | Region: " + obj[i].region + "
";

}

$('#result').html(strin);

},

error: function(response, status, error)

{

alert("Error");

}

});

的数据被发送到该站点curl.php,它发送一个卷曲请求到外部网站。我写了外部的草书,因为它是在同一个文件夹中,我们就应该像它是外部的,我们从它需要cURL数据(你知道作业)

所以,现在的URL看起来像这样

http://localhost/htmlAssignment/5/curl.php?type=town&region=Hampshire&hidden=hiddenFive

而且curl.php保存在变量这些参数,然后将其发送到Web service.php

$type = $_GET['type'];

$region = $_GET['region'];

$hidden = $_GET['hidden'];

$url = "http://localhost/htmlAssignment/webservice.php?type=" . $type . "&region=" .$region. "&hidden=".$hidden;

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

$output = curl_exec($ch);

curl_close($ch);

echo $output;

?>

的webservice.php

CHEC KS如果隐藏的价值是hiddenFive,什么是正确的,然后调用DB-功能

if(isset($_GET['type']) && isset($_GET['region']) && $_GET['hidden'] == 'hiddenFive')

{

$array = array();

$region = $_GET['region'];

$type = $_GET['type'];

$array = $db->getMultiDataPOI($type, $region);

echo json_encode($array);

}

我的数据库功能看起来像这样

function getMultiDataPOI($type, $region)

{

$getMultiSQL = "SELECT ID, name, type, country, region, lon, lat, description FROM pointsofinterest WHERE type = :type AND region = :region";

$getMultiPrepare = $this->prepare($getMultiSQL);

$getMultiPrepare->bindParam(':type', $type);

$getMultiPrepare->bindParam(':region', $region);

$getMultiPrepare->execute();

$getMultiResult = $getMultiPrepare->fetchAll();

return $getMultiResult;

}

这20秒钟后得到的数据通常和显示它应该,但它需要20秒,如果你问我什么是奇怪的。这么长时间以来可能会出现这个问题?正如我所说,我正在使用xampp和其他任何使用相同webservice的AJAX请求即时加载localhost。为什么这需要这么长时间?

这是一个屏幕,如果它从FireBug帮助。我希望你能阅读它。

6f5d326a67a2ddd197e753b07e003210.png

2013-04-23

devShuba

+0

你有你的列被索引看起来像查询需要很长时间。 –

2013-04-23 11:21:05

+0

开始隔离自下而上。首先对最内层的功能(DB功能)进行基准测试,然后移动到web服务等等。这应该确切地指出慢度开始出现的位置。当你发现问题时,调试起来要容易得多 - 现在对我们来说这只是一个猜测游戏。 –

2013-04-23 11:22:00

+0

你为什么不直接打电话给你的web服务? –

2013-04-23 11:22:19

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值