Page 1 of 1

time_t 4 bytes in a stream - evaluate in PHP?

Posted: Fri Sep 25, 2009 2:53 pm
by johnnylundy
Hi all.

Apple sends "Feedback" results as a stream of

4 bytes time_t, the date and time
2 bytes length of the next field (for now, always 32)
32 bytes of binary, a token to be converted to hex for display

So I have this 38-byte result. My SQL database stores each user's record as the "TIMESTAMP" data type.

Can someone point me in the right direction for what I need to do with this 4-byte "time_t" in order to be able to compare it to the SQL "TIMESTAMP"?

This is of course for my PHP script. I have to see if the value in the "time_t" is earlier than what is in that user's record in my SQL database.

Thanks

Re: time_t 4 bytes in a stream - evaluate in PHP?

Posted: Fri Sep 25, 2009 4:23 pm
by requinix
time_t is an integer, same thing that time gives you back... except for the representation.

Big-endian or little-endian for it? As in, if you get the value, then wait a second, and get the value again, does the first byte change or does the last byte change?

Re: time_t 4 bytes in a stream - evaluate in PHP?

Posted: Fri Sep 25, 2009 4:38 pm
by johnnylundy
tasairis wrote:time_t is an integer, same thing that time gives you back... except for the representation.

Big-endian or little-endian for it? As in, if you get the value, then wait a second, and get the value again, does the first byte change or does the last byte change?
Thanks for the reply.

All of the stream is big endian. 4 byte time_t, 2 byte length, 32 byte token.

I think I can use unpack() to parse it out with the format

Code: Select all

$result = fread($apns, 38);
$array = unpack("NnH32", $result);
or something like that. Then I have to figure out how to compare the date/time value to the one stored in my SQL database which is type "timestamp".

Re: time_t 4 bytes in a stream - evaluate in PHP?

Posted: Fri Sep 25, 2009 5:09 pm
by requinix
They're comparable as-is. Just numbers.

(And just "N" for the unpack format.)

Re: time_t 4 bytes in a stream - evaluate in PHP?

Posted: Fri Sep 25, 2009 5:18 pm
by johnnylundy
tasairis wrote:They're comparable as-is. Just numbers.

(And just "N" for the unpack format.)
I don't need the lowercase "n" for the short? The stream is an integer, a short, and a 32-byte string.

Ah, so timestamps are just 32-bit integers like time_t?

Re: time_t 4 bytes in a stream - evaluate in PHP?

Posted: Fri Sep 25, 2009 5:40 pm
by requinix
Oh, didn't realize you were doing all three parts at once. No, you got it right.

One kind of "timestamp" is the number of seconds since January 1 1970. C/C++'s time_t, the numbers you get from PHP functions like time and mktime, and MySQL's TIMESTAMP are all that type of data.

Re: time_t 4 bytes in a stream - evaluate in PHP?

Posted: Fri Sep 25, 2009 5:52 pm
by johnnylundy
tasairis wrote:Oh, didn't realize you were doing all three parts at once. No, you got it right.

One kind of "timestamp" is the number of seconds since January 1 1970. C/C++'s time_t, the numbers you get from PHP functions like time and mktime, and MySQL's TIMESTAMP are all that type of data.

OK - much appreciated!