Re: PHP 4.0 Bug #6080 Updated: fsockopen example uses "\n" for HTTP communication
| From: | Bjoern Hoehrmann | Date: | Fri, 11 Aug 2000 11:47:56 +0000 |
| Subject: | Re: PHP 4.0 Bug #6080 Updated: fsockopen example uses "\n" for HTTP communication | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-28589@lists.php.net to get a copy of this message | ||
* "Bug Database" <php-dev@lists.php.net> wrote:
| fixed in cvs
Fixed to \r\n
from
perldoc perlport
[...]
Newlines
In most operating systems, lines in files are terminated by newlines.
Just what is used as a newline may vary from OS to OS. Unix
traditionally uses \012', one type of DOSish I/O uses \015\012', and
Mac OS uses `\015'.
Perl uses `\n' to represent the "logical" newline, where what is logical
may depend on the platform in use. In MacPerl, \n' always means \015'.
In DOSish perls, \n' usually means \012', but when accessing a file in
"text" mode, STDIO translates it to (or from) `\015\012', depending on
whether you're reading or writing. Unix does the same thing on ttys in
canonical mode. `\015\012' is commonly referred to as CRLF.
Because of the "text" mode translation, DOSish perls have limitations in
using seek' and tell' on a file accessed in "text" mode. Stick to
seek'-ing to locations you got from tell' (and no others), and you are
usually free to use seek' and tell' even in "text" mode. Using
`seek'
or `tell' or other file operations may be non-portable. If you use
binmode' on a file, however, you can usually seek' and `tell' with
arbitrary values in safety.
A common misconception in socket programming is that \n' eq \012'
everywhere. When using protocols such as common Internet protocols,
\012' and \015' are called for specifically, and the values of the
logical \n' and \r' (carriage return) are not reliable.
print SOCKET "Hi there, client!\r\n"; # WRONG
print SOCKET "Hi there, client!\015\012"; # RIGHT
[...]
However, PHP is buggy with newlines. It makes \n always to LF which is wrong
on MacOS and DOS/Win32, as reported in Bug: 6079. It should be \x0d\x0a oder
\015\012 or something alike, otherwise it will break again if bug 6079 is
fixed.
regards,
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://www.bjoernsworld.de
am Badedeich 7 · Telefon: +49(0)4667/981ASK · http://bjoern.hoehrmann.de
25899 Dagebüll · PGP KeyID: 0xA4357E78 · http://learn.to/quote <---