1

I've got some PHP code on my server that talks to my PostgreSQL database. My iPhone app communicates with the PHP via HTTP GETs/PUTs/POSTs (this is only running on mobile devices, not via browsers). I need to return a large JSON result from the query of the database. The query results will be dynamic, so one user isn't necessarily going to get the same response as another. I'm not sure of the exact size at the moment, but I'd hazard a guess it's probably going to be up to 1MB or so. So I have two questions:

  1. Can I return a fairly large JSON string in PHP in response to an HTTP GET request?
  2. Is there a maximum or best maximum size that should be returned via HTTP GET?
  3. If I can do #1, then the rest is moot. If, however, this is either not possible or not a good idea, what would be the alternative way to retrieve this data for the client?

Thanks!

Architekt
  • 2,141
  • 1
  • 22
  • 27

1 Answers1

2

PHP can return Megabytes of data, no problem. As long as the server, client and network are ready to handle the transfer, there is no real size limit to data returned by HTTP GET. 1Mb should be no problem if the client (phone) is on a reasonable network connection.

The GET request itself has a size limit of a few Kb or so, but the response has no such limitations.

Go ahead and have fun!

Community
  • 1
  • 1
grebneke
  • 4,414
  • 17
  • 24
  • 1
    For clarity GET doesn't really have a cap, but the URL maximum length will be hit, its usually ~1600 characters depending the server's settings. – siva.k Jan 03 '14 at 05:37
  • @siva.k: As long as we are talking about the *request*, yes. The question is about the *response* though, so there should be no problem. – grebneke Jan 03 '14 at 05:39