Re: Re: PHP 4.0 Bug #6080 Updated: fsockopen example uses "\n" for HTTP communication
| From: | Hartmut Holzgraefe | Date: | Fri, 11 Aug 2000 12:28:59 +0000 |
| Subject: | Re: Re: PHP 4.0 Bug #6080 Updated: fsockopen example uses "\n" for HTTP communication | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-28592@lists.php.net to get a copy of this message | ||
Bjoern Hoehrmann wrote:
>
> * "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 -`?'Ã
> ‰ÁSô"qäµ\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.
no, php is not 'buggy with newlines', this is just one of the places
where it is more C-ish than PERL-ish (note that 6079 has been closed
as there is nothing to fix)
so '\r' is \015 and '\n' is \012 as long as an ASCII-based character
set is used and the only place where automatic conversion does occure
is with the fopen-interface that does take care of platform-dependant
line endings in files
especially when dealing with sockets it is important to have full
control over what to send out to the other side as different
protocols require different line endings
so please lets let '\n' be LF (linefeed or _n_ewline) and '\r' CR
(carriage _r_eturn) as they used to be instead of messing things
up with to much magic
the PERL way might be okay for what PERL was made for in the first
place (the tings the 'R' stands for) but it is a bad thing within
a client-server environment
PS:
maybe we should define some constants for things like local
line endings or path seperators similar to what JAVA has
--
Hartmut Holzgraefe
hartmut@six.de http://www.six.de +49-711-99091-77 fax:-99