简体   繁体   English

XmlHttpRequest vs cURL

[英]XmlHttpRequest vs cURL

I was wondering if anyone has done any testing on the speed differences of cURL and XHR (in regards to the time it takes to complete a request, or series of requests). 我想知道是否有人对cURL和XHR的速度差异进行了任何测试(关于完成请求或一系列请求所花费的时间)。

Specifically I'm wondering because I would like to use XHR to go to php script, and use cURL from there to grab a resource. 具体来说,我想知道因为我想使用XHR转到php脚本,并从那里使用cURL来获取资源。 The php page will ensure ensuring the data is in the right format, and alter it if it isn't. php页面将确保数据格式正确,如果不是,则更改数据。 I would like to avoid doing this on the javascript end because it's my understanding that if the users computer is slow it could take noticeably longer. 我想避免在javascript端执行此操作,因为我的理解是,如果用户计算机速度很慢,则可能需要更长时间。

If it makes a difference, all data will be retrieved locally. 如果它有所不同,将在本地检索所有数据。

There is no speed difference between the two. 两者之间没有速度差异。 You're comparing an HTTP request to an... HTTP request. 您正在将HTTP请求与... HTTP请求进行比较。 For our purposes they both do the exact same thing, only one does it in JavaScript and one in PHP. 出于我们的目的,他们都做了完全相同的事情,只有一个用JavaScript做,一个用PHP做。 Having a chain will take twice as long (probably more) since you're making a request to your server, and then your server is making a request to another server. 拥有一个链将花费两倍的时间(可能更多),因为您向服务器发出请求,然后您的服务器向另一台服务器发出请求。

I don't understand why you wouldn't want to just get the resource with JavaScript and scrap the PHP median. 我不明白你为什么不想用JavaScript获取资源并废弃PHP中位数。 I don't see any problem with doing it that way. 这样做我没有看到任何问题。 (Unless your data is on another domain, then it gets trickier, but it's still doable.) (除非你的数据在另一个域上,否则它会变得更棘手,但它仍然可行。)

If I understand the question correctly, the difference will be that XmlHttpRequest would be on the client side (javascript), and cURL would be on the server side (PHP) 如果我正确理解了这个问题,区别在于XmlHttpRequest将在客户端(javascript),而cURL将在服务器端(PHP)

This would impact performance one way or the other, depending on where the resource is (you say local), and how many concurrent requests you'll get. 这会以某种方式影响性能,具体取决于资源的位置(您说是本地),以及您将获得多少并发请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM