|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-12-15 01:05 UTC] sniper@php.net
[2004-12-15 21:36 UTC] wez@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 08:00:02 2025 UTC |
Description: ------------ an array holds elements of various types: ascii|integer|integer|integer|integer in a foreach loop, sending each element to a socket opened with fsockopen sends the elements as strings, not as the character type. gettype within the foreach loop shows that I'm sending dealing with the correct types: 16:39:54 SENT 'K' of type string 16:39:54 SENT '0' of type integer 16:39:54 SENT '0' of type integer 16:39:54 SENT '65' of type integer 16:39:54 SENT '31' of type integer fwrite is, according to the documentation, supposed to be binary safe. I think there's a bug in fwrite that has it send all elements as strings. Reproduce code: --------------- function send_back($sock, $msg, $ip, $port) { $fp = fsockopen("udp://$ip", "$port"); foreach ($msg as $msg_to_send) { fwrite($fp, $msg_to_send); echo date("H:i:s")." SENT '$msg_to_send' of type ".gettype($msg_to_send)." \n"; //seen server side } fclose($fp); } Expected result: ---------------- running a packet sniffer, I can see that what's being sent are strings: 15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP | 0000: 4b K 15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP | 0000: 30 0 15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP | 0000: 30 0 15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP | 0000: 3635 65 15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP | 0000: 3331 31 Actual result: -------------- Those last two (65 and 31) should be represented by single bytes, not two bytes.