performance - RESTful API in PHP - optimising successive requests? -
i'm working (for first time) on developing php application driven php restful api (probably using peej/tonic). coming application direct access might make 20 different database calls during course of page load, trying reconcile fact 20 api calls = 20x handshakes (which can improved guzzle persistent connections) 20x connections database.
i believe better programming , planning, can required api calls down 4-5 per page. @ point:
a) not worth considering latency of 5x database connections + 5x handshakes per page load on account of other available optimisations?
b) there existing method can mitigated i've far failed find?
c) believe violates principles of restful programming if had single api method gathered information other api endpoints (for instance, suppliers x=y products supplier), there documented method internal api interaction (particularly within peej/tonic or other frameworks).
thank wisdom in advance.
remember client should "making 'a request' of server," obliged fulfill "that request." server might "execute 20 different database queries" prepare response, , client need not know nor care.
the client's point-of-view becomes, "i care what tell me, not how did it."
if did wish send query-responses directly client, client "do dirty-work" these data, still design server request server did many queries, @ once, , sent of result-sets ... in one exchange.
your first priority should minimize number of exchanges take place. amount of data returned (within reason) secondary.
also consider that, "when server it, work naturally synchronized." when client issues multiple asynchronous requests, requests are, well, "asynchronous." consider strategy easier debug.
if server given "a request do," can validate request (thus checking client bugs), , perform number of database operations, perhaps in transaction
. strategy, puts server active role, much less complex interaction driven client server taking passive role.
Comments
Post a Comment