JrrMaster / php-for-android

Automatically exported from code.google.com/p/php-for-android
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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).

Original issue reported on code.google.com by nuclear...@gmail.com on 19 Feb 2012 at 4:41

GoogleCodeExporter commented 9 years ago
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.

Original comment by a...@gp-inc.ca on 29 Aug 2012 at 2:03

GoogleCodeExporter commented 9 years ago
Thanks for the effort. I'll try to release a new apk soon with your patch.

Original comment by ktulur on 29 Aug 2012 at 6:53

GoogleCodeExporter commented 9 years ago

Original comment by ktulur on 29 Nov 2012 at 9:34