I am currently working on a site. I designed it as an API so that it can easily interface with mobile devices as well as keep me completely separate from front end development. The intention was that the front end designer would use javascript\jQuery to make API calls. The API returns JSON so the front end designer would format the content appropriately. I noticed that instead of using jQuery to obtain this data he is using inline PHP to make the appropriate API calls using cURL to localhost and then echoing the JSON result and formatting it. Is this cause for concern since the server is essentially requesting itself. A new process is spawned, the server has to process a request AND response, etc. Is it better off for the remote clients to use jQuery to resolve the API calls or have the server cURL localhost and resolve them?
2
-
Obviously this is really bad from a design perspective since there was a mis-communication about how the API was supposed to be used, but usually shouldn't be a problem for performance (the details depend on a lot of specifics).Ben Lee– Ben Lee2012-03-13 23:06:31 +00:00Commented Mar 13, 2012 at 23:06
-
He was really free to do how he pleased so long as he got it done, and it does work. I highly suggested on jQuery as it seems more natural than cURLing yourself and asking yourself to get data. So long as there isn't a significant performance impact it's ok. Does anyone ever use an API in this manner?user974896– user9748962012-03-13 23:14:17 +00:00Commented Mar 13, 2012 at 23:14
Add a comment
|
1 Answer
It sounds like the performance issue here would be that PHP might be getting loaded up more than it needs to:
JQuery -> RESTful API built on PHP
vs
JQUERY -> PHP cURL Call -> cURL -> RESTful API built on PHP
Each call takes an extra use of PHP, as you said spawning another process. The extra use of cURL is no biggie (it's lightweight), but the extra use of PHP might be an issue if you are going to have heavy usage (say 100 concurrent, but really depends on your server, and many other factors).