3

I have a client/server app in which the client sends objects in the form of JSON to the server which runs a PHP script and then places this data into a database.

The problem is that decoding is done with the json_decode function which seems to work on strings not streams. Is there a way to take the inpustream from the HTTP request and use a streaming JSON parser to reduce the memory foot print.

I come from a java background where there are a couple of frameworks like jackson , xtream for this. Is there a PHP equivalent? Otherwise it seems I'll run into scalability issues.

bluphoenix
  • 338
  • 2
  • 6
  • 12

2 Answers2

1

I wrote a little pure PHP JSON streaming parser that works on streams. Hope that it's the kind of thing you're looking for.

Rob Gonzalez
  • 579
  • 1
  • 6
  • 19
0

You may want to try parse yourself the php://input stream (with fopen()) but IMHO every SAPI (apache-mod-php, fastcgi) are waiting the end of the HTTP request before sending it to php so it won't be useful.

voondo
  • 2,533
  • 1
  • 16
  • 21
  • thanks for the answer. It seems there is nothing out of the box or even framework to do this. The only other thing i can think of is for the client to break up the data to send and use multiple requests (this seems like a waste though and a lot of extra HTTP overhead) Your comment about SAPI parsing the HTTP request before php gets it is interesting I will have to do some more research – bluphoenix Dec 21 '11 at 02:10