I'm trying to only cURL parts of an array generated by a game API. More or less I'd like to skip over elements I don't need to speed up the query. Is this possible? Example
[1] => Apple
[0] => Stem
[1] => Leaf
[2] => Orange
I'd only like to download the data under Apple. Thanks!
This is not possible, if you don't have control over the API
If you have control over the API, you could let it accept additional parameters, which are evaluated by the webservice and have to be added to your HTTP request. So a parameter &details=apple could be evaluated in the backend like this
details = extractFromRequestParams("details");
if (details==="apple") {
printOutDetailsForApple();
} else {
printOutEverything();
}
In case you do not have control over the API, your cURL request will always do the whole request, grab everything from the answer, and only afterwards gets you access to that answer.
When you're talking about rather large responses, it could be worth to replacing the cURL library with something slighlty lower level, that gives you more control over reading from the HTTP request. You then would be processing parts of the answer as they come in already, and could stop reading when you got everything you need from the response. And probably save a few bytes from being transmitted. You can't skip parts in the beginning, of course, so the usefulness of this approach depends on the position of the data which is important for you in the whole answer. And this requires constantly flushing on the server side, which you don't have control over.