To Know about php://input
Posted: Sat Nov 29, 2008 12:58 am
Dear Developers,
I have used php to read raw post data from URL which is called from Java. For that I have used file_get_contents('php://input'). From Java I sent byte array as a URL request, In that, first 4 bytes tells me how many bytes to be read from Input stream. I used to get the first 4 bytes and convert that in to Integer. So Now i know How many bytes remaining from 4th bytes in the byte array. I could not able to read further remaining bytes when I run loop second time based on offset,maxlen of bytes.
In this case file_get_contents('document.txt',false,null,offset,maxlen) works fine in a loop. but
file_get_contents('php://input',false,null,offset,maxlen) does not works fine in a loop.
Can any one suggest a solution?
Here my code
<php
$start=0;
$how_much=4;
$string = file_get_contents('php://input',false,null,$start,$how_much);
$first_4bytes = str_split($string);
$total_no_bytes = byteArrayToInt($first_4bytes,0);
$log = "Total No. of. bytes is $total_no_bytes";
write_log($logfile,$filename,$log,"");
while(true)
{
$start = ($start+$how_much);
$how_much=4;
$log ='';
$log .= "\nStart position is $start and $how_much bytes suppose to be get";
$string = file_get_contents('php://input',false,null,$start,$how_much);
$second_4bytes = str_split($string);
$app_len = byteArrayToInt($second_4bytes,0);
$log .= "\nAppointment length is $app_len";
if($app_len == 0)
{
$log .= " So Going to Beak the loop";
write_log($logfile,$filename,$log,"");
break;
}
$start=($start+$how_much);
$how_much=$app_len;
$log .= "\nNow, Start position is $start and $how_much bytes suppose to be get";
$string = file_get_contents('php://input',false,null,$start,$how_much);
$app_bytes = str_split($string);
write_log($logfile,$filename,$log,"");
Parse_Appointment($app_array,$mClndr_login);
if($start == $total_no_bytes)
{
$log = "All bytes have been read, So Going to Break the Loop";
write_log($logfile,$filename,$log,"");
break;
}
}
In above code, I could not able to get the second_4bytes from php inputsteam.?
What is the wrong here?
?>
I have used php to read raw post data from URL which is called from Java. For that I have used file_get_contents('php://input'). From Java I sent byte array as a URL request, In that, first 4 bytes tells me how many bytes to be read from Input stream. I used to get the first 4 bytes and convert that in to Integer. So Now i know How many bytes remaining from 4th bytes in the byte array. I could not able to read further remaining bytes when I run loop second time based on offset,maxlen of bytes.
In this case file_get_contents('document.txt',false,null,offset,maxlen) works fine in a loop. but
file_get_contents('php://input',false,null,offset,maxlen) does not works fine in a loop.
Can any one suggest a solution?
Here my code
<php
$start=0;
$how_much=4;
$string = file_get_contents('php://input',false,null,$start,$how_much);
$first_4bytes = str_split($string);
$total_no_bytes = byteArrayToInt($first_4bytes,0);
$log = "Total No. of. bytes is $total_no_bytes";
write_log($logfile,$filename,$log,"");
while(true)
{
$start = ($start+$how_much);
$how_much=4;
$log ='';
$log .= "\nStart position is $start and $how_much bytes suppose to be get";
$string = file_get_contents('php://input',false,null,$start,$how_much);
$second_4bytes = str_split($string);
$app_len = byteArrayToInt($second_4bytes,0);
$log .= "\nAppointment length is $app_len";
if($app_len == 0)
{
$log .= " So Going to Beak the loop";
write_log($logfile,$filename,$log,"");
break;
}
$start=($start+$how_much);
$how_much=$app_len;
$log .= "\nNow, Start position is $start and $how_much bytes suppose to be get";
$string = file_get_contents('php://input',false,null,$start,$how_much);
$app_bytes = str_split($string);
write_log($logfile,$filename,$log,"");
Parse_Appointment($app_array,$mClndr_login);
if($start == $total_no_bytes)
{
$log = "All bytes have been read, So Going to Break the Loop";
write_log($logfile,$filename,$log,"");
break;
}
}
In above code, I could not able to get the second_4bytes from php inputsteam.?
What is the wrong here?
?>