|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-08-28 21:37 UTC] jani@php.net
[2007-08-28 22:09 UTC] bugs at nazarenko dot net
[2007-08-28 22:22 UTC] bugs at nazarenko dot net
[2007-08-29 08:59 UTC] jani@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 02:00:01 2025 UTC |
Description: ------------ Using CLI, if more than 1 process is forked with pcntl_fork() both functions mt_rand() and rand() return same values in all child processes. This only happens when there was a call to mt_rand()/rand() in the parent process before forking. Reproduce code: --------------- Compiled latest available snapshot under Solaris 10 and SuSE Linux 10.1 with the following configure options: --disable-all --disable-cgi --enable-pcntl --disable-ipv6 The test script is the following: <?php echo mt_rand(0,255)."\n"; # comment this line out to see difference for ($i=0; $i<3; $i++) { if (pcntl_fork() == 0) { die(mt_rand(0,255)."\n"); } } ?> Expected result: ---------------- Expected result is 4 random numbers generated by 4 different Unix processes (1 parent and 3 children). Actual result: -------------- The actual result (both on Solaris and Linux) is that all 3 numbers generated by the children are the same. Now comment out the first echo command belonging to the parent process and the result is 3 random numbers generated by children.