Miscellaneous bugfixes for PHP 5.3.x on Windows, backported from PHPRandom