Export to GitHub

php-for-android - issue #10

Responses from the RPC socket over 1KB result in an error


Posted on Feb 19, 2012 by Helpful Monkey

What steps will reproduce the problem?

  1. Make a call to an RPC method which returns a large amount (>1kB) of data such as 'contactsGet' or 'smsGetMessages'. 2. 3.

What is the expected output? What do you see instead?

The decoded JSON should be returned from the method call. Instead, the terminal shows some PHP notices on like 54/55 of Android.php about accessing undefined properties. A number of subsequent calls will return an empty response (id, result and error all null).

What version of the product are you using? On what operating system?

Whichever version sl4a automatically installed when I added it through the interpreters menu. Running on Android 4.0.1 on Galaxy Nexus.

Please provide any additional information below.

The issue arises because the socket_read call on line 49 is only reading 1kB of data from the socket. If the returned response is greater than 1kB then an incomplete JSON object is returned, and decoding fails (resulting in the notices). Subsequent requests fail because of the data remaining in the socket which causes subsequent reads to contain another partial JSON object.

The simplest patch, and the one that fixed the issue for me, was simply to up the amount read in the single socket_read call. I upped it from 1024 to 1048576 (1MB). The 'proper' fix would be to loop until socket_read returns a blank string (which, as per the PHP manual page, signifies no more data to be read).

Comment #1

Posted on Aug 29, 2012 by Helpful Hippo

Just reinstalled this today and was disappointed to find this not fixed. :(

For anyone who needs to patch this manually in the future, Android.php is located on your SD card under com.irontec.phpforandroid/extras/php/Android.php.

On line 49 change '1024' to '1048576' and it will handle RPC responses up to 1MB.

Comment #2

Posted on Aug 29, 2012 by Massive Dog

Thanks for the effort. I'll try to release a new apk soon with your patch.

Comment #3

Posted on Nov 29, 2012 by Massive Dog

(No comment was entered for this change.)

Status: Started

Labels:
Type-Defect Priority-Medium