I've ran into a problem, but can't tell whether it is PHP or Windows' command line. When a PHP script tries to echo UTF-8 characters into cmd with UTF-8 codepage loaded, the process stops unexpectedly. Here is a case:
test1.php:
<?php
error_reporting( -1 );
echo 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЫЭЮЯ', "\n";
echo "OK";
?>
test2.php:
<?php
error_reporting( -1 );
echo 'ASCII: ABCDEFGHIJKLMNOPQRSTUVWXYZ', "\n";
echo 'UTF-8: АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЫЭЮЯ', "\n";
echo 'UTF-8: АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЫЭЮЯ', "\n";
echo "OK";
?>
(Both test1.php and test2.php are saved in UTF-8 without BOM.)
The command prompt log:
e:\tests>chcp 1252
Active code page: 1252
e:\tests>php -f test1.php
АБВГДЕЁЖЗРЙКЛМНОПРСТУФХЦЧШЩЫРЮЯ
OK
e:\tests>php -f test2.php
ASCII: ABCDEFGHIJKLMNOPQRSTUVWXYZ
UTF-8: АБВГДЕЁЖЗРЙКЛМНОПРСТУФХЦЧШЩЫРЮЯ
UTF-8: АБВГДЕЁЖЗРЙКЛМНОПРСТУФХЦЧШЩЫРЮЯ
OK
e:\tests>chcp 65001
Active code page: 65001
e:\tests>php -f test1.php
e:\tests>php -f test2.php
ASCII: ABCDEFGHIJKLMNOPQRSTUVWXYZ
UTF-8: АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЫЭЮЯ
e:\tests>
While in 1252 mode, all characters get echoed (although not correctly, of course). But in 65001 (UTF-8) mode test1 stalls on the very first character while test2 stalls on the first one of the second UTF-8 row.
PHP version is:
PHP 5.4.13 (cli) (built: Mar 15 2013 02:07:14)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
Windows is XP SP3.
Update:
1) If I change echo to:
$f = fopen( 'php://stdout', 'w' );
fwrite( $f, ... );
...
close( $f );
it works.
2) If I redirect the output:
e:\tests>php -f test1.php > out.log
it also works (with echo).
But what is wrong with the first case?

type test2.php(or any other UTF-8 file), it works.