Take the 2-minute tour ×

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).

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. The php page will ensure ensuring the data is in the right format, and alter it if it isn't. 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.

If it makes a difference, all data will be retrieved locally.

share|improve this question
If all data is local, why are you using HTTP to get it? –  acrosman Jun 10 '09 at 0:54
I still need to pass items along to the data, and let it be processed. The 'data' are scripts that execute and return a response. –  Ian Elliott Jun 10 '09 at 1:16
add comment

2 Answers

up vote 3 down vote accepted

There is no speed difference between the two. You're comparing an HTTP request to an... HTTP request. For our purposes they both do the exact same thing, only one does it in JavaScript and one in 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. 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.)

share|improve this answer
I realized that both are HTTP requests, but I thought that there may be differences in how they are implemented. In the end you have the same result, but there could be many ways of getting to such. But based on this I assume that they are implemented almost identically to the point where they execute and terminate at the same time? –  Ian Elliott Jun 10 '09 at 1:18
Well obviously they aren't exactly the same, but the differences are minor enough that you don't need to worry about them. –  Sasha Chedygov Jun 10 '09 at 1:18
add comment

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)

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.

share|improve this answer
add comment

Your Answer


